I have defined enqueueMessage
function to enqueue the message to rabbitMQ queue. In the first line of the function I am creating channel. Which means every time I call enqueueMessage
a channel is created. Is this the right approach or should I created top level channel
variable and reuse it?
If I create top level channel should I do some more coding to handle case channel gets closed automatically for some reason (network broke)
export async function enqueueMessage(queue: string, message: object) {
const channel = await connection.createChannel();
await channel.assertQueue(queue);
channel.sendToQueue(queue, Buffer.from(JSON.stringify(message)));
}