node-amqp icon indicating copy to clipboard operation
node-amqp copied to clipboard

Clean up Connections/Channels

Open dchankhour opened this issue 10 years ago • 5 comments

I'm creating additional Connection to RabbitMQ and creating Queue on those additonal RabbitMq Connections for each User in my application. However, i'm trying to clean those connections and channels when the user closes the application, but it seems i'm only able to Destroy the queues i have created with no issue. Clearing those connections using connection.end will cause an error in my application in regard to amqp.* although i'm sending an empty string '' to create the queues.

Is there an option or a way i can clear Connections/Channels when a user closes or refreshes the application?

dchankhour avatar Apr 02 '14 19:04 dchankhour

I am not sure about your question. Could you put some code and the error?

On Wed, Apr 2, 2014 at 9:35 PM, Dani Chankhour [email protected]:

I'm creating additional Connection to RabbitMQ and creating Queue on those additonal RabbitMq Connections for each User in my application. However, i'm trying to clean those connections and channels when the user closes the application, but it seems i'm only able to Destroy the queues i have created with no issue. Clearing those connections using connection.end will cause an error in my application in regard to amqp.* although i'm sending an empty string '' to create the queues.

Is there an option or a way i can clear Connections/Channels when a user closes or refreshes the application?

Reply to this email directly or view it on GitHubhttps://github.com/postwait/node-amqp/issues/324 .

jgato avatar Apr 02 '14 21:04 jgato

I currently have my global RabbitMQ connection:

                var conn = amqp.createConnection({
                    url: config.rabbit.url[app.get('env')]
                }, 
                {
                    defaultExchangeName: 'AppServerWorkExchange',
                    defaultExchangeAutoDelete: false,
                    reconnect: false
                });

Once the user logs in, i need to create a new queue from a new connection:

                var tempConn = amqp.createConnection({
                    url: brokers[x].Uri
                });

                tempConn.on('ready', function() {

                    tempConn.exchange(brokers[x].ExchangeName, {
                        type: 'topic',
                        autoDelete: false
                    }, function(exch) {

                        //Create Private Queue
                        var eventQueue = tempConn.queue('', {
                            exclusive: true
                        }, function(q2) {

Once the user logs out, i want to clear the connection and the queue.

dchankhour avatar Apr 02 '14 21:04 dchankhour

I would recommend you to have only one connection, and then create exchanges, queues through it. In any case... I guess you clear the qeueue with queue.destroy() and the connection with tempConn.end(), isnt it? which error do you have?

On Wed, Apr 2, 2014 at 11:05 PM, Dani Chankhour [email protected]:

I currently have my global RabbitMQ connection:

var conn = amqp.createConnection({ url: config.rabbit.url[app.get('env')] }, { defaultExchangeName: 'AppServerWorkExchange', defaultExchangeAutoDelete: false, reconnect: false });

Once the user logs in, i need to create a new queue from a new connection:

var tempConn = amqp.createConnection({ url: brokers[x].Uri });

            tempConn.on('ready', function() {

                tempConn.exchange(brokers[x].ExchangeName, {
                    type: 'topic',
                    autoDelete: false
                }, function(exch) {

                    //Create Private Queue
                    var eventQueue = tempConn.queue('', {
                        exclusive: true
                    }, function(q2) {

Once the user logs out, i want to clear the connection and the queue.

Reply to this email directly or view it on GitHubhttps://github.com/postwait/node-amqp/issues/324#issuecomment-39383560 .

jgato avatar Apr 03 '14 05:04 jgato

I'm currently not receiving any errors, but the issue is that after i do: queue.unbind queue.destory queue.unsubscribe

I do see that the queue is cleared up , but the number of channels does not go down.

dchankhour avatar Oct 31 '14 00:10 dchankhour

I have the same problem. My solution is to create connection and channel once when initialising the app. Then use it later. Looking forward for better solution.

dattran92 avatar Feb 23 '16 09:02 dattran92