Event Published Multiple Times

Just want to confirm the intended behavior of Axon, versus what I’m seeing in my application. We have a customized Kafka publisher integrated with the Axon framework.

The issue I’m seeing is as follows: (1) I publish a command (e.g. CreateServiceCommand) which hits the constructor of the ServiceAggregate, and then (2) A ServiceCreatedEvent is applied to the aggregate. (3) We see the domain event persisted in the backend and published over the EventBus (where we have a Kafka consumer).

All well and good, but suppose I publish that same command again with the same aggregate identifier. I do see the ServiceCreatedEvent being applied to the aggregate in the debugger, but since a domain event record already exists with that key, nothing is persisted to the backend. Again, all well and good, however I see the ServiceCreatedEvent being published out to Kafka and consumed by our listener, which is unexpected behavior.

I’m wondering whether this is the expected behavior of Axon, or if our Kafka integrations ought to be ensuring we’re not publishing duplicate events over the EventBus.

Hi @blackcompe, I believe this is a duplicated of this question on stackoverflow and you already have an answer provided by @Steven_van_Beelen.

Hope this is sufficient.

It has. Feel free to delete the thread if you like.

I believe you, as the starter of the thread, should be able to mark responses as the answer @blackcompe. I’d wager @lfgcampos his response could be marked as such. The thread on it’s own still has value, even though it targets a different location.