Axon 4 leveraging Kafka with multiple topics


We are looking to implement Axon saga leveraging Kafka for event based messaging.
Would like to use a different message topic for each saga.
From the documentation and examples I have reviewed so far, looks like the only way is to configure multiple KafkaPublisher beans (one for each topic).
However the code snippet in the documentation seems to be specific to Axon 3, could anyone share Axon 4 equivalent?

Hi Gaurav,

the Kafka extension is currently under (heavy) development. We’re very close to releasing it and have been working to update the documentation as well.
Currently, the way to configure a different topic for each Saga is to create a Publisher bean per Saga. We do have plans to allow for you to specify the topic(s) for each message at runtime. We’re not sure if that feature will make it in the first release, but it will likely follow shortly.

Just wondering, normally a Saga receives events and sends out commands. Are you planning to post those commands on Kafka, or are you planning to read events from Kafka? In the latter case, you should look at the [Streamable|Subscribable]KafkaMessageSource instead.

Hope this helps.

Hello Allard,

Thanks a lot for your reply.

Actually we are not using command gateway and send out events from Saga (instead of commands) and intercept events in the saga with appropriate identifier.
This works out well however with only 1 topic and multiple saga’s, we were ending up defining distinct events for each saga even though they signified the same thing.

Would be great if you could provide an example of configuring a different publisher bean for each saga. The examples I referred to seem to be of Axon v 3.x.

Following is our event model for implementing saga – right now we need to define at least 8 distinct events for each saga (assuming each saga has minimum 2 participants).
These events could be generalized as follows:
InitiateParticipantEvent (1 for each participant)
ParticipantSuccessEvent (1 for each participant)
ParticipantFailureEvent (1 for each participant)
However, as we use only 1 channel of communication (1 topic), we can’t use generic events as they get intercepted by all saga managers and event handlers from each microservice, if we use different topics – 1 for each saga, we might be able to use generic events.

Hi Gaurav,

I’m not sure if I completely follow what you’re trying to accomplish.

It does feel like you’re trying to create Saga-specific “channels” on which to publish and receive Events. I’d be wary of such an approach. In general, systems benefit most from Events that describe specific occurrences on the “business level” and share those relatively publicly within their bounded context. Generic events tend to be technical and more focussed on the current design, rather than the domain. That design is more likely to change.