How to use Axon with an EventStore for event sourcing and an EventBus for Hibernate repository persistence?

Hello all,

I have extended https://github.com/Qyotta/axon-eventstore (Greg Young’s EventStore Java client with Axon wrapper) to support Axon 3.0.4 and included as a reference in a spring boot POC I am creating.

In a configuration file I added:

// EventStore extends EventBus

@Bean
public EventStore eventStore() {
    final EsEventStore esEventStore = new EsEventStore(new EventStoreClient(new EsContextDefaultImpl(EventStoreSettings.withDefaults()
            .host("http://127.0.0.1:2113")
            .build())));

    return esEventStore;
}

Since I'm using JPA to persist the data to a postgresSQL database I got an error saying I needed an EventBus (assuming axon spring boot starter configuration detected this), so I added to the same config file:

// Since EventStore extends EventBus, now we have 2 buses

I tried removing the SimpleEventBus bean and change my EventStore bean to:

@Bean
public EventStore eventBus() {
    final EsEventStore esEventStore = new EsEventStore(new EventStoreClient(new EsContextDefaultImpl(EventStoreSettings.withDefaults()
            .host("[http://127.0.0.1:2113](http://127.0.0.1:2113/)")
            .build())));

    return esEventStore;
}

I no longer get the error of a missing EventBus, but I still don’t get the event handler to fire :frowning:

Can you confirm the handlers are properly subscribed to your EventStore (actually, a processor will subscribe on behalf of the handlers)?

I actually have been thinking about that exactly… I was assuming Axon would magically take care or that, but now I’m thinking maybe the EventStore implementation (in my case EsEventStore) is responsible for that, or at least for providing an implementation or the subscribe method (I believe added to SubscribableMessageSource interface which EventBus extends).

The library that I extended to implement Axon 3.0.4 didn’t override the subscribe method, since that didn’t exit in Axon 2.4.x I suppose. I thought I could wing it by not implementing that method and I was going to return new NotImplementedException, but I just left the auto-generated “return null;”. Now that I replaced it with the exception I get it thrown just as I start the application.

I will attempt to add a proper implementation to the subscribe method and go from there…

Thanks,
Bruno

Implementing the subscribe method did the trick. My event handlers are now firing.

I’m also using AMQP in this POC and it is also working now that EsEventStore implements the subscribe method correctly. Although, it sends a message to rabbitMQ that contains all the data in the aggregate… which is not the desired functionality. I would want the message to contain the entity guid. Rabbit will then push the message to another service that will use the query api to get the object. We don’t want it in the rabbitMQ message because this queue will be public.

I was wondering if I could intercept the message before it is sent to the queue and change what is being sent, but without affecting what is being sent to the EventStore. Not sure if MessageDispatchInterceptor is the best candidate for this and if there is any example out there on how to use it…

Regards,
Bruno

I have created a separate thread for this second question:

https://groups.google.com/forum/#!topic/axonframework/SIN006m23dg

Hi Bruno. My team is maintaining the EventStore Java Lib on github. I am happy it worked well for you. Would you mind to share your changes in order the library to work with Axon 3 as a pull request?
Many thanks in advance.

- siamak

Hi Siamak,

I’d be happy to share the code with you. There are a few things I think we still need to implement to handle transaction I believe. But I’m yet to understand how transactions work in Axon. I am actually going to post another thread on this group about that exactly.

Also the code I wrote was for a POC, just to get us going, so it may be a bit too naive… but I’d be glad to have your input on it.

If it’s ok with you, I will create a branch and commit the code to that branch.

I had emailed you a few weeks ago about this, but maybe you thought it was spam or something. I’m glad you found this thread. I colleague of mine also posted an issue on github regarding licensing. Apparently, if there is no License document stating that the code is free to use, we actually can’t use it. MIT is a good simple template for licensing. Hope you don’t mind adding that on there…

Regards,
Bruno