Amqplib的sendtoqueue()即使队列确实存在
”的队列
名为“ Test_queue
我用Amqplib创建了一个 !'
也没有错误
即使名为“ Test_queue”的队列不存在如何在队列不存在时如何获得错误,
!
const amqp = require('amqplib');
const sendMsg=async ()=>{
const connection = await amqp.connect('amqp://localhost');
const ch = await connection.createConfirmChannel()
const msg= 'hello world'
const QUEUE_NAME = 'test_queue'
ch.sendToQueue(QUEUE_NAME, Buffer.from(msg),{},function(err, ok) {
if (err !== null) {
console.log(err);
} else {
console.log('sent message successfully!');
}
})
// await ch.close();
// await connection.close();
}
sendMsg();
I created a queue named 'test_queue' with amqplib
then I deleted the 'test_queue' from the admin page of rabbitmq (http://localhost:15672/#/queues)
but when I excute the following code, it shows 'sent message successfully!'
there is no error even if the queue named 'test_queue' does't exist
How to get an error when queue doesn't exist?
Thanks for any help!
const amqp = require('amqplib');
const sendMsg=async ()=>{
const connection = await amqp.connect('amqp://localhost');
const ch = await connection.createConfirmChannel()
const msg= 'hello world'
const QUEUE_NAME = 'test_queue'
ch.sendToQueue(QUEUE_NAME, Buffer.from(msg),{},function(err, ok) {
if (err !== null) {
console.log(err);
} else {
console.log('sent message successfully!');
}
})
// await ch.close();
// await connection.close();
}
sendMsg();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果将强制性标志添加到SendToqueue,则任何无法路由到队列的消息都将发送回发布者。因此,从您的示例中,您需要:
然后,您可以使用相同的频道对象处理返回:
If you add the mandatory flag to sendToQueue any message which cannot be routed to a queue will be sent back to the publisher. So from your example you would need:
You can then handle the return using the same channel object: