Axon and rabbitMQ broker

Hello,
I just want to know, when the axon framework publish the events on RabbitMQ. I don’t know if this happens inside the apply-method, that is called from the commandHandler or when the commandGateway.send(—) method is called.

Just another question by the way:
Which approach is better: Publish directly the events after they has been saved in eventstore or to have a scheduler (runs every 2 seconds) that selects all the pending events (let’s say 100 events in a run) and then published them to the broker.

Any help will be appreciated

cheers
William

Hi William,

events are usually sent to external message brokers in the “prepareCommit” phase of the Unit of Work. This is the first stage after your (command) handlers have been executed, but before any of the changes have been committed. You can configure the RabbitMQPublisher to work transactionally. In that case, it will send the data in the “prepareCommit” phase and send the commit (or rollback) to Rabbit in the “commit” phase (where database commits also take place).

Note that this process is not 100% guaranteed atomic across systems. It is theoretically possible that events are committed into once source, but not in the other. To work around that issue, you can commit only to the event store, and use another mechanism (as you describe) to read from the event store and push the events to Rabbit. You will have higher reliability, at the cost of slightly higher latency.

Cheers,

Hi Allard,
thanks for your answer. what do u mean with " It is theoretically possible that events are committed into once source, but not in the other."?

cheers
William

Hi William,

I meant that it’s possible that a commit succeeds toward the database, and then fails towards Rabbit, or vice versa. The commits are somewhat coordinated, but it’s not an atomic operation. Generally, a failure would only happen in case one of the two systems goes down in the commit stage. A scenario where even 2-phase commit wouldn’t have helped.

Cheers,