atomic event consistency between event store and published message (2PC)

My application requires storing the events in the database and also publish the events to a queue. How does axon manages the transaction when the event published needs to be saved in database(mysql/oracle) and the event needs to be pushed to rabbbitmq/ kafka.

I do not want to use 2 phase commit for this but at the same time, I want to ensure that event is successfully published to rabbitmq and also stored in the database.
For cases such as either database or rabbitmq is not available, the transaction needs to be atomic.

What is the general recommendation here?

Can I just publish message to rabbitmq as part of command processing and listen to the event on a queue and store the event in the eventstore?

Eventuate is one framework that avoids 2PC by only persisting the events in JPA store and then reads the data from data store (i believe transaction logs in case of mysql) to publish events. I want to know how axon handles the persisting the events and publishing messages.


Check out the SpringAMQPPublisher. It will automatically publish events to AMQP after they are stored in the Event Store (or published on the bus). You can make the SpringAMQPPublisher ‘transactional’. In that case it will publish events in a transaction, that it will commit when the transation to the event store has also committed. Not 2PC, just 2 transactions.