你能解释一下使用Nodejs使用端口9092而不是zookeeper端口2181的kafkaClient吗?
var kafka = require('kafka-node'),
Producer = kafka.Producer,
KeyedMessage = kafka.KeyedMessage,
client = new kafka.Client(),
producer = new Producer(client),
km = new KeyedMessage('key', 'message'),
payloads = [
{ topic: 'topic1', messages: 'hi', partition: 0 },
{ topic: 'topic2', messages: ['hello', 'world', km] }
];
producer.on('ready', function () {
producer.send(payloads, function (err, data) {
console.log(data);
});
});
producer.on('error', function (err) {})
较新的 Kafka 客户端不再需要直接与 Zookeeper 对话。他们只需要与 Kafka 交谈。
我是一名优秀的程序员,十分优秀!