I did fresh installation of Apache Kafka 0.10.1.0.
I was able to send / receive messages on command prompt.
While using Producer / Consumer Java Example, I am not able to know group.id parameter on Consumer Example.
Let me know on how to fix this issue.
Below is Consumer Example I had used:
public static void main(String[] args) {
Properties props = new Properties();
props.put("bootstrap.servers", "localhost:9092");
props.put("group.id", "my-topic");
props.put("enable.auto.commit", "true");
props.put("auto.commit.interval.ms", "1000");
props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props);
try {
consumer.subscribe(Arrays.asList("my-topic"));
ConsumerRecords<String, String> records = consumer.poll(100);
System.err.println("records size=>"+records.count());
for (ConsumerRecord<String, String> record : records)
System.out.printf("offset = %d, key = %s, value = %s%n", record.offset(), record.key(), record.value());
}
catch (Exception ex){
ex.printStackTrace();
}
finally {
consumer.close();
}
}
After running the command for consumer, I can see the messages (on the console) posted by producer. But unable to see the messages from java program
bin\windows\kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic my-topic --from-beginning
group.id
for your kafka cluster by looking into$KAFKA_HOME/config/consumer.properties
. There you can see the line#consumer group id
. Use this value and your code will work. You can group multiple consumers to same group by giving same value ofgroup.id
in this file. – vindev