繁体   English   中英

在RabbitMq中assertQueue和send To Queue之间有什么区别

[英]what is the difference between assertQueue and send To Queue in RabbitMq

我找到了rabittMq中发送字符串的示例和队列中的接收但我不清楚这些方法 - assertQueuesendToQueue

send.js

var amqp = require('amqplib/callback_api');

amqp.connect('amqp://localhost', function(err, conn) {
  conn.createChannel(function(err, ch) {

              var q = 'hello';
                var msg = 'Hello World! - '+i;

                ch.assertQueue(q, {durable: false});                    
                ch.sendToQueue(q, new Buffer(msg));
                console.log(" [x] Sent %s", msg);
  });
  setTimeout(function() { conn.close(); process.exit(0) }, 1000);
});

receive.js

var amqp = require('amqplib/callback_api');

amqp.connect('amqp://localhost', function(err, conn) {          //amqp://localhost
  conn.createChannel(function(err, ch) {
    var q = 'hello';

    ch.assertQueue(q, {durable: false});
    console.log(" [*] Waiting for messages in %s. To exit press CTRL+C", q);
    ch.consume(q, function(msg) {
      console.log(" [x] Received %s", msg.content.toString());
    }, {noAck: true});
  });
});

从你的例子来看,

assertQueue检查“hello”队列,如果它不存在则会创建一个。

sendToQueue将消息放入“hello”队列。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM