I'm working with 2 express microservices, with 1st one(product) responsible for Product queue and second(Bid) for Bid queue. The channel and connection are established when the server starts itself. In one particular endpoint for product service data is first send to Bid queue where it is processed in Bid service and after a db request it is sent back to product queue which is consumed within the first endpoint itself.
The problem is the functionality is working fine for the first api call. But on subsequent calls I'm getting - 'nodejs cannot set headers after they are sent to the client'. Attaching the body of api call below.
channel.sendToQueue(
"BID",
Buffer.from(
JSON.stringify({
payload: req.body
})
)
);
return new Promise((resolve, reject) => {
channel.assertQueue("PRODUCT");
channel.consume("PRODUCT", (data) => {
let { payload } = JSON.parse(data.content);
console.log('Consuming from Second service', payload)
resolve('payload')
});
}).then(resp => {
return res.json(resp);
}).catch(err => {
console.log('errrrr', err)
})