Hello!
I've tried to interact with kafka in docker from cp-docker-images (branch 5.0.0-post). I've implement simple message listening code:
const client = new kafka.Client("zookeeper:2181");
const consumer = new kafka.Consumer(client, [{ topic: "test30", partition: 0 }], { autoCommit: false });
consumer.on("message", (message) => {
console.log("Got message", message)
});
Then I've run docker and create topic
$ docker-compose up -d
$ docker-compose exec broker kafka-topics --create --zookeeper zookeeper:2181 --replication-factor 1 --partitions 1 --topic test30
Then I've send one message:
$ docker-compose exec broker kafka-console-producer --broker-list localhost:9092 --topic test30
>hello!
And this is what I've got:
$ node .
Got message { topic: 'test30',
value: 'hello!',
offset: 0,
partition: 0,
highWaterOffset: 1,
key: null }
Got message { topic: 'test30',
value: '',
offset: 0,
partition: 0,
highWaterOffset: 1,
key: '' }
Two messages one of them has zero message and offset.
If I try consumer manually I've got just one message:
$ docker-compose exec broker kafka-console-consumer --bootstrap-server localhost:9092 --topic test30 --from-beginning
hello!
^CProcessed a total of 1 messages
But it's getting worse when I try to send one more message it start to emitting 'message' signal infinitely:
...
Got message { topic: 'test30',
value: 'world',
offset: 1,
partition: 0,
highWaterOffset: 2,
key: null }
Got message { topic: 'test30',
value: '',
offset: 0,
partition: 0,
highWaterOffset: 2,
key: '' }
Got message { topic: 'test30',
value: 'world',
offset: 1,
partition: 0,
highWaterOffset: 2,
key: null }
Got message { topic: 'test30',
value: '',
offset: 0,
partition: 0,
highWaterOffset: 2,
key: ''
...
How can I handle that?
Best regards!
Can you try with version 3.0?
@hyperlink I've just try to change the version in package.json manually and... It helps!
It's really fix the problem
Thank you very much! =)
Does it mean that 2.6.1 version is deprecated? I've installed it with
$ yarn add kafka-node
command
I'm glad that worked for you.
Does it mean that 2.6.1 version is deprecated?
We don't have bandwidth to support older releases.
I thought yarn just used npm's repository? Not familiar with it.
Yes, it's kind of wrapper for npm
Anyway problem is solved
Thank you once again
Most helpful comment
Can you try with version 3.0?