Custom configuration for Java client?

Hi,

By default the JVM client seems to be using the Akka config, which
reads custom settings from application.conf. However, I want to keep
all my settings in my own file, and thus create my own Config object.
I can easily do that, but it seems like the code has hardcoded getting
the default config (see SubscriptionActor:16 for example), which then
uses application.conf instead.

Is there any plan for fixing this, or do I really need to put all
EventStore client config in a separate application.conf?

regards, Rickard

Actually you can create instance of SubscriptionActor on your own with own configuration.

Overall idea was to use application.conf to override settings, but it is possible to pass Config object, however you would need a bit more code for plumbing everything together.

Hi Yaroslav,

Unfortunately what you said does not make sense, since
EsConnectionFactory has a method that takes Settings. It's just that
internally it is ignored, by SubscriptionActor. I would consider that
a bug, that should be fixed (shouldn't be too hard).

If creating a SubcriptionActor on my own is a workaround, is there an
example of how to do this?

/Rickard

It’s just that
internally it is ignored, by SubscriptionActor

Looks like a bug - https://github.com/EventStore/EventStore.JVM/issues/46

Not sure what kind of settings you want to override, however this one may help you for now:

    final ActorSystem system = ActorSystem.create();
    final Settings settings = new SettingsBuilder()
            .address(new InetSocketAddress("127.0.0.1", 1113))
            .defaultCredentials("admin", "changeit")
            .build();
    final ActorRef connection = system.actorOf(ConnectionActor.getProps(settings));
    final ActorRef observerActor = system.actorOf(SubscriptionObserverActor.props(observer));
    final ActorRef subscription = system.actorOf(StreamSubscriptionActor.props(connection, observerActor, streamId, fromNumberExclusive, resolveLinkTos, credentials))
    final Closeable closeable = ActorCloseable.apply(observerActor);

``

Hi!

Thanks for your help, but the code doesn't seem to work. Maybe it's
not Java code?

Specifically:
* I have a Position.Exact with commit/prepare numbers as long.
EventNumber.Exact constructor takes int. How do I create that
properly?

* There is no SubscriptionObserverActor.props(observer) method. The
only one I can see takes a ClassTag as well. What is that, and how do
I create one?

* StreamSubscriptionActor.props takes a stream id. Can I set that to
null to subscribe to all streams?

* StreamSubscriptionActor.props takes credentials. Why is that
supplied there, when the settings with credentials have already been
passed to ConnectionActor.getProps(settings)?

thanks, Rickard

Looks like you are talking about subscribe to all streams case, thus replace StreamSubscriptionActor.props with SubscriptionActor.props

  • StreamSubscriptionActor.props takes credentials. Why is that
    supplied there, when the settings with credentials have already been
    passed to ConnectionActor.getProps(settings)?

This has been designed similarly to .Net client, basically you can easily override credentials for every subscription, command, etc

Ok, hence the Option, got it.

The remaining problem now is the SubscriptionObserverActor.props
method, which needs a ClassTag. What is that, and how do I create one?

regards, Rickard

scala.reflect.ClassTag.apply(evenstore.IndexedEvent.getClass))

``

Something like this

Doesn't compile. Maybe that's not Java code?

Any other way to create a ClassTag?

/Rickard

Are there any workarounds for this?

I just realized that being able to provide custom client config is not
just nice to have, but essential in at least one case: my app has a
primary event source, and an "upstream", when in staging. Staging will
be getting all the production events, so as to be a reasonably
accurate representation of what production looks like. For this to
work I have to be able to create clients twice, with different config.

/Rickard

StackOverflow to the rescue. Here's how to do it:

scala.reflect.ClassTag$.MODULE$.apply(IndexedEvent.class)