Reputation: 21
We want to use the microservice pattern and Apache Kafka as an event driven message stream.
We have different use cases that we want to implement with Kafka, but we dont know how to do this with Kafka.
Maybe we have a misconception there or Kafka isnt the right choice for us.
Service/Consumer B -> @KafkaListener(topics = "EventName", groupId = "GROUP1")`
Service/Consumer C -> @KafkaListener(topics = "EventName", groupId = "GROUP2")
Service/Consumer D -> @KafkaListener(topics = "EventName", groupId = "GROUP3")
...
I dont know if this is the correct way to achieve what we want to achieve.
Next we want service A to wait for all 5 consumers to finish their task, before further processing. Is that even possible or is it a misconception on my side? The next thing we want is that certain events should only be processed once (exactly once), but i think this is possible with disabling auto commits and handling the partition offset manual. I did not try this yet, and maybe i did mess things up there :-) but what ive read, this is possible. (Please correct me if it is not possible)
But how to save/return their result? They cant write in the passed data object, because of data consistency problems. Should they return their result and Service A stores the result in the data object?
Follow up question: Shouldnt we pass the data object at all and maybe the consumer should ask for the data with an extra event?
Maybe we should not use Kafka, maybe we should changes our patterns/architecture completely
Let me sum up what i want to achieve and what not:
Upvotes: 0
Views: 480
Reputation: 20591
If the initial event you're publishing has a correlation ID (something unique to that event), then each of the 5 consumers can publish an event to a Kafka topic saying that that consumer processed the event.
In general, exactly-once processing of a message is not possible. There's a very limited exception to this in Kafka (basically, if the processing consists only of generating a message and producing that message back to Kafka: any processing beyond this voids the exactly-once promise), but you'll almost certainly have to choose between at-most-once and at-least-once (you can get fairly close to exactly-once with at-least-once and a consumer which can remember what it's done).
Upvotes: 0