I have a spring boot application. I wish to implement a functionaly that consumes from a Kafka topic and for every consumed message it calls another method that does some processing on the message and then stores it in a database. The source kafka topic has 12 partitions. I want to create 6 or 12 kafka consumers under the same consumer group. All of the consumers will consume messages from Kafka and call the function. I am not able to get to a good design for this. Can someone help me ?
2 Answers
We have pretty the same need for a topic with 4 partitions, we created a consumer group with 2 members, and we assigned each member ( instance of our consumer) two partitions. If you are using spring you can select how many members will be created by instances with this parameter:
# For Kafka concurrency
spring.kafka.listener.concurrency=2
If you are using the Kafka library this parameters should be in the parameters of your consumer. Be aware to not exceed you number of threads availables.
The source kafka topic has 12 partitions. I want to create 6 or 12 kafka consumers under the same consumer group
You can either set spring.kafka.listener.concurrency
or you can simply run multiple Java processes on the same machine or multiple machines with the same configs.
There's nothing else you need to do as the rest is handled by the Consumer API