我想问一下,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
})
}
}
}