在Nodejs中关闭与AMQP库的连接

发布于 2025-02-04 12:51:05 字数 658 浏览 5 评论 0原文

我将AMQP用于我的应用程序。收到所有消息队列后,我想关闭与消费者AMQP的连接。但是,我不知道该如何处理。如果有人帮助我,我将非常感激和感谢。谢谢

var amqp = require('amqplib');

amqp.connect('amqp://localhost').then(function(conn) {
process.once('SIGINT', function() { conn.close(); });
return conn.createChannel().then(function(ch) {

 var ok = ch.assertQueue('hello', {durable: false});

 ok = ok.then(function(_qok) {
  return ch.consume('hello', function(msg) {
    console.log(" [x] Received '%s'", msg.content.toString());
  }, {noAck: false});
});

return ok.then(function(_consumeOk) {
  console.log(' [*] Waiting for messages. To exit press CTRL+C');
  
 });

 })
 }).catch(console.warn);

I use AMQP for my application. I want to close the connection to the consumer AMQP after all the message queues have been received. However, I don't know how to handle it. I will be very grateful and appreciated if someone help me. Thank you

var amqp = require('amqplib');

amqp.connect('amqp://localhost').then(function(conn) {
process.once('SIGINT', function() { conn.close(); });
return conn.createChannel().then(function(ch) {

 var ok = ch.assertQueue('hello', {durable: false});

 ok = ok.then(function(_qok) {
  return ch.consume('hello', function(msg) {
    console.log(" [x] Received '%s'", msg.content.toString());
  }, {noAck: false});
});

return ok.then(function(_consumeOk) {
  console.log(' [*] Waiting for messages. To exit press CTRL+C');
  
 });

 })
 }).catch(console.warn);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

少女的英雄梦 2025-02-11 12:51:05

conn.close()此关闭功能将关闭连接

conn.close() this close function will be close the connection

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文