I have a GET request (using express-js):
api.get("/test/req", async function(req, res){
try{
let result = '';
var reqId = req.id;
await producer.send({
topic: `producer${clusterWorkerId}`,
messages: [
{
headers: {
'id': reqId
},
value: 'Hello KafkaJS user!',
partition: 0
},
],
});
let promise = new Promise(async (resolve, reject) => {
await consumer.run({autoCommitInterval: 5,
eachMessage: async({ topic, partition, message }) => {
console.log('GET MESSAGE');
console.log({
topic: topic,
partition: partition,
message: message.value.toString(),
worker_id: clusterWorkerId})
resolve(message.value.toString());
}
})
});
result = await promise;
console.log({result: result});
res.status(200).json({"id": result});
}
catch(error){
console.log('ERROR:', error);
}
});
I try to make for each worker different topic (worker 1 - consumer1, worker 2 - consumer2, etc). When I send GET request first 5 times, it works fine, but when I send it again it seems like consumer doesn't resolve a result, and I don't have any idea why. When specific consumer get message again (second time) - it doesn't work. Why doest it happen?