WolfiG
WolfiG

Reputation: 1163

Apache Kafka consumer consumes messages with "partition" option, but not with "group" option

I am running a plain Apache Kafka server (version 3.4.1) which I would like to connect to a Telegraf consumer. The Telegraf [[inputs.kafka_consumer]] plugin has the option to consume by Kafka "group". When staring Telegraf, I get an error message

[inputs.kafka_consumer] Error in plugin: consume: kafka server: Request was for a consumer group that is not coordinated by this broker

Hence, I started to investigate my setup by using the Kafka console tools and found that when executing

 ./kafka-console-consumer.sh --bootstrap-server myserver:9092 --topic test --partition 0

and sending messages via kafka-console-producer.sh, these messages pop up in the console "consumer" window as expected.

In contrast to this, when I run

 ./kafka-console-consumer.sh --bootstrap-server myserver:9092 --topic test --group my-group

nothing happens in the "consumer" window. Furthermore, the command

./kafka-consumer-groups.sh --bootstrap-server myserver:9092 --list

yields nothing.

What do I have to do to cause the consumer with the "group" option to "see" the messages produced to the topic "test"? Ultimately, how can I solve the Telegraf error?

Update: it would be great if you provide a set of Kafka console commands which reliably produces and consumes messages to a consumer group.

Upvotes: 0

Views: 772

Answers (1)

Neeraj
Neeraj

Reputation: 109

I can't really comment on why Telegraf is not working, however....

If you have a large number of partitions in your topic, it can take a really long while before you start seeing messages on the console.

So, using the partition id is the right approach. But just need to be patient at the command-line.

Out of interest, how long did you wait for the output from console consumer ?

If you need to know the partition id, you will need to use a custom program to compute it based on the key. (You could have a look at the murmur2 source code on the Kafka github repository and try to create a simple command line tool to compute the partition id using the key).

However, using --group option will only set the consumer group id of your instance of the kafka-console-consumer.sh. If you have other consumers that are part of this consumer group, then I believe some rebalancing should occur as some partitions will get moved to your kafka-console-consumer.sh client.

Upvotes: 0

Related Questions