Kafka消费消息样例配置文件
样例配置文件
private KafkaConsumer<String, String> createConsumer() {
Properties props = new Properties();
props.put("bootstrap.servers", kafkaServers);
props.put("group.id", MiscUtil.getIp());
props.put("key.deserializer", StringDeserializer.class.getName());
props.put("value.deserializer", StringDeserializer.class.getName());
//最佳实践中提到,不要使用 auto commit,只在消息处理成功才提交
props.put("enable.auto.commit", "false");
KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props);
consumer.subscribe(Collections.singletonList(topicSync));
return consumer;
}
原创:做时间的朋友

浙公网安备 33010602011771号