An available library is sarama (or its expansion sarama-cluster) however no consumer group example are provided, not in sarama nor in sarama-cluster.
I do not understand the API. May I have an example of creating a consumer group for a topic?
An available library is sarama (or its expansion sarama-cluster) however no consumer group example are provided, not in sarama nor in sarama-cluster.
I do not understand the API. May I have an example of creating a consumer group for a topic?
There is no need to use sarama-cluster library. It is DEPRECATED for apache kafka integration.
Sarama
original library itself provide a way to connect to kafka cluster using consumer group.We need to create client and then we initialize consumer group where we create claims and wait for message channel to receive message.
Initializing client :-
Connection to consumer group :-
Start consuming messages from topic partition :-
The last part is to wait for message channel to consume messages. We need to implement all of the functions (three) to implement
ConsumerGroupHandler
interface.For more information on kafka using golang check sarama library.
The consumer group is specified by the second argument of the cluster consumer "constructor". Here's a very basic sketch:
And so you'll have a consumer belonging to the specified consumer group.