Kafka消费者调查api没有将记录返回到低超时。 如果我在轮询中增加超时值,则记录即将到来。 我无法理解这种逻辑。请按照以下代码提供帮助:
public ConsumerRecords<String, Map<String, String>> subscribeToQueue(String topic, QueueListener q) {
Properties props = new Properties();
props.put("bootstrap.servers", "localhost:9092");
props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
props.put("value.deserializer", "com.intuit.eventcollection.queue.KafkaJsonDeserializer");
props.put("group.id", "test");
props.put("enable.auto.commit", "true");
props.put("auto.commit.interval.ms", "1000");
props.put("session.timeout.ms", "30000");
props.put("auto.offset.reset", "earliest");
// Figure out where to start processing messages from
KafkaConsumer<String, Map<String, String>> kafkaConsumer = new KafkaConsumer<String, Map<String, String>>(
props);
kafkaConsumer.subscribe(Arrays.asList(topic));
ConsumerRecords<String, Map<String, String>> records = null;
// Start processing messages
try {
records = kafkaConsumer.poll(100);
答案 0 :(得分:0)
如果在指定为轮询超时(超时)的时间段内没有发布新的未使用消息,则轮询将不返回任何内容。