zhanghuafeng24 2022-03-06 16:55 采纳率: 0%
浏览 13

rabbitmq的队列问题

我想问一下,rabbitmq在publish时是不是可以不用定义和绑定队列 ?下面这个例子好像就没有绑定队列

const bson = require('bson')
var amqp = require('amqplib/callback_api');
var uploadDataExchange = "iothub.events.upload_data"
var updateStatusExchange = "iothub.events.update_status"
var commandRespExchange = "iothub.events.cmd_resp"
var dataRequestRespExchange = "iothub.events.data_request"
var currentChannel = null;
amqp.connect(process.env.RABBITMQ_URL, function (error0, connection) {
if (error0) {

    console.log(error0);
} else {
    connection.createChannel(function (error1, channel) {
        if (error1) {
            console.log(error1)
        } else {
            currentChannel = channel;
            channel.assertExchange(uploadDataExchange, 'direct', {durable: true})
            channel.assertExchange(updateStatusExchange, 'direct', {durable: true})
            channel.assertExchange(commandRespExchange, 'direct', {durable: true})
        }
    });
}

});
class NotifyService {
static notifyUpdateStatus({productName, deviceName, deviceStatus}){
var data = bson.serialize({
device_name: deviceName,
device_status: deviceStatus
})
if(currentChannel != null) {
currentChannel.publish(updateStatusExchange, productName, data, {
persistent: true
})
}
}
}

  • 写回答

1条回答 默认 最新

  • _雪菜肉丝面_ 2022-03-06 17:09
    关注

    交换机也会用到队列,广告:https://blog.csdn.net/qq_37284843/article/details/122368178

    评论

报告相同问题?

问题事件

  • 修改了问题 3月6日
  • 修改了问题 3月6日
  • 修改了问题 3月6日
  • 创建了问题 3月6日

悬赏问题

  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统