Multiple EventStore

Hi all,

It is possible to use axon framework with more than one EvenStore?? Let me explain, in DDD one of the basic things is split the business in subdomains/bounded context etc… if we have a very big application and lot of events is better to have different event stores for the different parts in the application but is this posible with Axon?? for example in the same app have two TrackingProcessors/EventListeners that each one listen to a different EventStore?

Best Regards

Hi Jorge,

Yes, that’s absolutely possible and also reasonable in the situation you sketch.

Axon, especially in combination with Spring Boot autoconfiguration, gives a lot of sensible defaults. If you have JPA on the classpath, it will configure a single JpaEventStorageEngine, use that to construct a single EmbeddedEventStore, and if you’re using tracking event processors, those will be using this single event store as their messageSource. But you can configure all of this in a different way if you like, using multiple event stores and choose which tracking event processors go to which event store.

In the enterprise version of our AxonDB event store offering, we support the notion of having multiple contexts, which are logically separated event stores, for exactly the reason you mention.

Kind regards,

Hi Frans,

Thanks for your reply :slight_smile:

Putting a concrete example for use MongoDB as Event Store I understand how to setup different “MongoEventStorageEngine”, basically i can create different “MongoTemplates” using different “MongoClient” that point to different MongoDB servers or different data bases, and here is where i start to have doubt:

  1. I suppose that i should create a “EmbeddedEventStore” for each “MongoEventStorageEngine” right? i have seen the AxonAutoConfiguration class and iñm not sure what is a “MessageMonitor”?
  2. Reading the documentation seems like “Tracking Processors” are created automatically using the package names (https://docs.axonframework.org/part-iii-infrastructure-components/event-processing#assigning-handlers-to-processors), so how can we organize/setup the different Tracking Proccessor to get events from different event stores/EmbeddedEventStore? is using the “source” property? how can we choose this “source” for each EmbeddedEventStore?
  3. Talking about a Saga, how are the event processor assigned to a Saga? can a Saga listen for event from multiple EventStores??

Best Regards

Hi Jorge,

Let me go through your questions one by one.

  1. I suppose that i should create a “EmbeddedEventStore” for each “MongoEventStorageEngine” right? i have seen the AxonAutoConfiguration class and iñm not sure what is a “MessageMonitor”?

Your assumption is correct. The easiest thing to have multiple ‘streamable event sources’ is to introduce several EmbeddedEventStores, all with their own EventStorageEninge. The MessageMonitor can be wired into your EventBus, as well as your CommandBus and EventProcessors to get message ingestion metrics based on Dropwizard/Metrics.

  1. Reading the documentation seems like “Tracking Processors” are created automatically using the package names (https://docs.axonframework.org/part-iii-infrastructure-components/event-processing#assigning-handlers-to-processors), so how can we organize/setup the different Tracking Proccessor to get events from different event stores/EmbeddedEventStore? is using the “source” property? how can we choose this “source” for each EmbeddedEventStore?

Yes, Axon will automatically wire everything for you in a Spring environment, but you can very easily override that. In Axon 3.3 you can use the EventProcessingConfiguration (versions below 3.3 have the EventHandlingConfiguration) to instantiate your TrackingEventProcessors. You do this by using the registerTrackingEventProcessor() function. The name parameter is the name of the processing group you’ve given to your Tracking Event Processor. The important part in configuring your Tracking Event Processor this way, is by providing the right StreamableMessageSource (which I referred to in answer 1). The StreamableMessageSource is an interface which the EmbeddedEventStore implements. As you’ve specified several EmbeddedEventStores, you can select the rigth one to be used by the right TrackingEventProcessor.

  1. Talking about a Saga, how are the event processor assigned to a Saga?

Saga’s receive their events by means of Event Processors as well, which is configurable by using the SagaConfiguration. This class allows you to configure your saga to use either a Subscribing or a Tracking Event Processor (so, identical to regular event handling components).

can a Saga listen for event from multiple EventStores??

No, this currently is not an option, although we do see this as a reoccurring question. Hence we do have it on the roadmap to be introduced in our products (Framework, AxonHub and AxonDB), eventually. As such I cannot give you a time frame when this will be introduced.

Hope this helps you out for now Jorge.

Cheers,
Steven

Hi Steven

Is there any update already for a saga listening to multiple event stores?

Thanks!

Laura Winnen

Hi Laura,

Yes, I can actually give you a hand on the matter.
As of Axon Framework 4.2, there is the option to specify a MultiStreamableMessageSource as the StreamableMessageSource for a TrackingEventProcessor.

It thus does mean your Saga is required to be backed by a TrackingEventProcessor.

The MultiStreamableMessageSource provides a builder, allowing you to provide several StreamableMessageSource instances to it.

Axon’s EmbeddedEventStore is one such StreamableMessageSource you can use here for example.

If you are using Axon Server on the other hand, leverage the MultiStreamableMessageSource to connect several contexts together.
The way to achieve this is by using the AxonServerEventStore#createStreamableMessageSourceForContext(String) method, which will return you just such a StreamableMessageSource to give to a MultiStreamableMessageSource.

Trusting this helps you out further Laura!

Cheers,
Steven