Java Code Examples for org.apache.kafka.clients.consumer.internals.NoOpConsumerRebalanceListener

The following examples show how to use org.apache.kafka.clients.consumer.internals.NoOpConsumerRebalanceListener. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: skywalking   Source File:    License: Apache License 2.0 5 votes vote down vote up
public void run() {
    Properties consumerProperties = new Properties();
    consumerProperties.put("bootstrap.servers", bootstrapServers);
    consumerProperties.put("", "testGroup2");
    consumerProperties.put("", "true");
    consumerProperties.put("", "1000");
    consumerProperties.put("auto.offset.reset", "earliest");
    consumerProperties.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
    consumerProperties.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
    KafkaConsumer<String, String> consumer = new KafkaConsumer<>(consumerProperties);
    consumer.subscribe(topicPattern, new NoOpConsumerRebalanceListener());
    int i = 0;
    while (i++ <= 10) {
        try {
            Thread.sleep(1 * 1000);
        } catch (InterruptedException e) {

        ConsumerRecords<String, String> records = consumer.poll(100);

        if (!records.isEmpty()) {
            for (ConsumerRecord<String, String> record : records) {
      "header: {}", new String(record.headers()
      "offset = {}, key = {}, value = {}", record.offset(), record.key(), record.value());

Example 2
public void subscribe(Collection<String> topics) {
  subscribe(topics, new NoOpConsumerRebalanceListener());
Example 3
Source Project: incubator-gobblin   Source File:    License: Apache License 2.0 2 votes vote down vote up
 * Subscribe to a kafka topic
 * TODO Add multi topic support
 * @param topic
public void subscribe(String topic) {
  this.consumer.subscribe(Lists.newArrayList(topic), new NoOpConsumerRebalanceListener());