jwalton / node-amqp-connection-manager

Auto-reconnect and round robin support for amqplib.
528 stars 105 forks source link

Receiver test dont use consume function define in channelWrapper. #370

Closed SSANSH closed 4 months ago

SSANSH commented 4 months ago

https://github.com/jwalton/node-amqp-connection-manager/blob/master/examples/receiver.js

When you declare a consumer inside a setup, the consume function use by code is not the function define into channelWrapper but the function of amqplib. This is a shame because we loose all management of cancel message for example. For using the function define on channelWrapper we have to call then directly after instance created by ChannelWrapper.

Something like this:

var amqp = require('..'); var QUEUE_NAME = 'amqp-connection-manager-sample1' // Handle an incomming message. var onMessage = function(data) { var message = JSON.parse(data.content.toString()); console.log("receiver: got message", message); channelWrapper.ack(data); } // Create a connetion manager var connection = amqp.connect(['amqp://localhost']); connection.on('connect', function() { console.log('Connected!'); }); connection.on('disconnect', function(err) { console.log('Disconnected.', err.stack); }); // Set up a channel listening for messages in the queue. var channelWrapper = connection.createChannel({ setup: function(channel) { //channelhere is a regular amqplibConfirmChannel. return Promise.all([ channel.assertQueue(QUEUE_NAME, {durable: true}), channel.prefetch(1), ]); } }); channelWrapper.waitForConnect() .then(function() { console.log("Listening for messages"); }); channelWrapper.consume(QUEUE_NAME, onMessage)

is it really what is expected?