-
Notifications
You must be signed in to change notification settings - Fork 467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
about long-lived connection and message to send #46
Comments
|
Yes, as Michael says, connections are supposed to be long-lived, as are channels. In your code above, I think you're trying to have a single exported function that will send a message, and being stymied because you have promises rather than "real" values. You can dereference a promise more than once, so the easiest way to fix it is to phrase your function like this: var q = 'task-queue';
var channel = connection.then(function(conn) {
var ok = conn.createChannel();
ok = ok.then(function(ch) {
return ch.assertQueue(q, {durable: true})
.then(function() { return ch; }); // swap
});
return ok;
});
exports.sendtomq=function(msg) {
channel.then(function(ch) {
ch.sendToQueue(q, new Buffer(msg), {persistent:true});
});
}; The only tricky bit really is the swapping the assertQueue result for the channel itself (marked |
Wow!thank you very much! what you said is really I want. After using your code,I can send my real message well. |
Sorry,I have just a question.Need I to close the channel after sending the message?
|
No; in fact you don't want to, usually, because it will stop you sending more messages with the channel. The original example code closes the channel because it's only sending one message before exiting. |
Thanks for your great work.
I am a newbie of node & rabbitmq,now i want to use rabbitmq to send message and receive. I got your example code and updated it. I have two questions about it.
1>can i keep a long-lived connection to send message and don't close it?
2>how can i send message with my data?
senddao.js,
The text was updated successfully, but these errors were encountered: