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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: skywalking   Source File: CaseController.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    Properties consumerProperties = new Properties();
    consumerProperties.put("bootstrap.servers", bootstrapServers);
    consumerProperties.put("group.id", "testGroup2");
    consumerProperties.put("enable.auto.commit", "true");
    consumerProperties.put("auto.commit.interval.ms", "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) {
                logger.info("header: {}", new String(record.headers()
                  .headers("TEST")
                  .iterator()
                  .next()
                  .value()));
                logger.info("offset = {}, key = {}, value = {}", record.offset(), record.key(), record.value());
            }
            break;
        }
    }

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