Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bash-4.3# ./kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group test
- Note: This will only show information about consumers that use the Java consumer API (non-ZooKeeper-based consumers).
- Consumer group 'test' has no active members.
- TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAG CONSUMER-ID HOST CLIENT-ID
- test_topic 0 42 43 1 - - -
- public void consumeMessages() {
- Properties props = new Properties();
- props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
- props.put(ConsumerConfig.GROUP_ID_CONFIG, "test");
- props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
- props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
- try (KafkaConsumer < String, String > kafkaConsumer = new KafkaConsumer < > (props)) {
- kafkaConsumer.subscribe(Collections.singletonList("test_topic"));
- ConsumerRecords < String, String > consumerRecords = kafkaConsumer.poll(5000);
- for (ConsumerRecord < String, String > consumerRecord: consumerRecords) {
- System.out.printf("offset = %d, message = %s%n", consumerRecord.offset(), consumerRecord.value());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement