Closing exchange's channels
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,
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..
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 .
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?
+1