AxonIQ / axon-server-se

Axon Server - Standard Edition
Other
131 stars 42 forks source link

Publish distributed domain event #390

Open tomijuarez opened 2 years ago

tomijuarez commented 2 years ago

Based on this discussion, where I found a problem trying to adopt Axon, I'd like to know if there's any way to atomically publish a domain event using a message bus and saving the domain event in the datastore. This would be pretty useful since distributed applications really need this kind of mechanism with microservices that are not part of the same bounded context. For example, a store that publishes a purchase domain event and the interesting microservices could be a notification service (to email the stakeholders), billing service, analytics service, etc.

Is it possible to support this feature conditionally based on the chosen datastore? For example, this could be easy if it's backed on DynamoDB with streams and MongoDB Change Streams. Of course, a dispatcher is needed to read that change event from the DB, parse it to a valid representation and send it to a message broker (Kafka, RabbitMQ, whatever).

zambrovski commented 2 years ago

Hi,

I believe Axoniq Forum is a better place for this discussion.

If the event is published and you are using EventSourcing it will be stored in Event Store. A projection, using a Tracking Processor will get this events delivered and processed in order and might send mails or do whatever... the processor is triggered by its own scheduler opening a Unit of Work for every event (aka transaction)...

Does it answer your question?

Cheers

Simon

tjuarezupgrade commented 2 years ago

Hi Simon. Is there any reference to those projectors on AxonIQ or should we implement that manually?

zambrovski commented 2 years ago

Hi,

you usually implement them on your own. Essentially, you declare a component to have some event handlers and decide what to do with those events... So in Spring, a @Component annotated bean with some methods annotated with @Eventhandler... By specifying the @ProcessingGroup you are able to configure the behaviour of the processor responsible for dispatching the events to those component. Default is tracking processor - own tracking token, own thread run in a Unit of Work... If you use something like Spring Data for example, you might want to create updates of your entities in the event handler and persist them into a RDBMS - then every event delivery will run in an own transaction... In order to operate, the tracking event processor manages a tracking token - pointing to the index of processor. The processor checks behind the scenes the index in the token and compares it to the index in the event store - and tries to "keep-up"... It is a good idea to persist the tracking token in the same persistence technology as the projection itself... so in case you use RDBMS for persistence you should save the token in a database too. All this information is a very fast-forward from the official AxonIQ reference documentation... Consider reading the architecture concepts first and then jump to event section: https://docs.axoniq.io/reference-guide/axon-framework/events