Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. bash-4.3# ./kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group test
  2. Note: This will only show information about consumers that use the Java consumer API (non-ZooKeeper-based consumers).
  3.  
  4. Consumer group 'test' has no active members.
  5.  
  6. TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAG CONSUMER-ID HOST CLIENT-ID
  7. test_topic 0 42 43 1 - - -
  8.  
  9. public void consumeMessages() {
  10. Properties props = new Properties();
  11. props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
  12. props.put(ConsumerConfig.GROUP_ID_CONFIG, "test");
  13. props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
  14. props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
  15.  
  16. try (KafkaConsumer < String, String > kafkaConsumer = new KafkaConsumer < > (props)) {
  17. kafkaConsumer.subscribe(Collections.singletonList("test_topic"));
  18. ConsumerRecords < String, String > consumerRecords = kafkaConsumer.poll(5000);
  19. for (ConsumerRecord < String, String > consumerRecord: consumerRecords) {
  20. System.out.printf("offset = %d, message = %s%n", consumerRecord.offset(), consumerRecord.value());
  21. }
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement