我正在尝试运行一个kafka消费程序,以便从名为“test2”的主题获取消息
我使用的是kafka 0.9api
Properties props = new Properties();
props.put("bootstrap.servers", "localhost:9092");
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("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props);
consumer.subscribe(Arrays.asList("test2"));
while (true) {
ConsumerRecords<String, String> records = consumer.poll(100);
for (ConsumerRecord<String, String> record : records)
System.out.printf("offset = %d, key = %s, value = %s", record.offset(), record.key(), record.value());
}
}
此代码来自kafka consumer api 0.9的官方文档
下图更清楚地说明了情况
eclipse控制台
有没有解决这个问题的建议
先谢谢你
1条答案
按热度按时间zkure5ic1#
只需在构建路径中添加slf4jjar并尝试