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

Closing exchange's channels

Open jgato opened this issue 12 years ago • 4 comments

Hi there,

I am implementing a node.js server to publish messages with rabbitmq. So, the server stablish and manage the connection during the initiating process.

Then, each time I have to pubish something I create a connection with the appropiated exchange:

connection.exchange(.....)

And then I make the publish process:

exchange.publish("", message, { persistant: 2 });

I have realized, this will create a new channel each time I make connection.exchange. In a server with thousand of publish messages it is a big issue.

So, now... after publish I close the exchange's connection (no the connection with the server), in order to close the channel.

   exchange.publish("", message, {
        persistant: 2
    });
   exchange.close()

Is this the right way of proceeding?

An estrange issue, after closing the exchange's connection, if I try to publish, the messages, of course, is not send it, but I dont even receive and error:

exchange.on('close', function(){ 
    console.log("closed exchange's channel");
    exchange.publish("", "{}", {
        persistant: 2
    });
});

pretty estrange??

many thanks and regards,

jgato avatar Oct 03 '13 09:10 jgato

the key is to only declare the exchange once, and then reuse it, this is because node-amqp implicitly opens a "channel" each time you call connection.exchange. Channels should be semi-long-lived, not opened and closed over and over again, if you want any kind of performance..

carlhoerberg avatar Oct 04 '13 06:10 carlhoerberg

Great, this is what I have in mind as a future solution :( Maybe I will have to priorize that...

But still, it is extrange I dont receive and error after publising on a closed channel...

On Fri, Oct 4, 2013 at 8:02 AM, Carl Hörberg [email protected]:

the key is to only declare the exchange once, and then reuse it, this is because node-amqp implicitly opens a "channel" each time you call connection.exchange. Channels should be semi-long-lived, not opened and closed over and over again, if you want any kind of performance..

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

jgato avatar Oct 04 '13 06:10 jgato

Any update on this? I am experiencing the same issue, is there a code sample on how to use the exchange connection as a singleton?

AliUz avatar Apr 29 '15 07:04 AliUz

+1

serhatates avatar Mar 06 '17 14:03 serhatates