node.js - AMQP RabbitMQ 获取错过的已发布消息
问题描述
当在 rabbitmq 上使用 1:1 的 send/listen 时,服务会保留尚未被侦听器侦听或确认的消息,以便当侦听器启动时,它会收到积压并被清除。如何或需要什么配置才能使其也适用于 1:many(类似扇出)的发布/订阅?
我正在为 nodejs 使用 amqplib
解决方案
Rabbitmq 队列应该是持久的
这确保在尝试使用队列之前声明队列
durable: true
});
**sample code**
var amqp = require('amqplib/callback_api');
amqp.connect('amqp://localhost', function(error0, connection) {
if (error0) {
throw error0;
}
connection.createChannel(function(error1, channel) {
if (error1) {
throw error1;
}
var queue = 'task_queue';
var msg = process.argv.slice(2).join(' ') || "Hello World!";
channel.assertQueue(queue, {
durable: true
});
channel.sendToQueue(queue, Buffer.from(msg), {
persistent: true
});
console.log(" [x] Sent '%s'", msg);
});
setTimeout(function() {
connection.close();
process.exit(0)
}, 500);
});
----------
推荐阅读
- qt - Qml TreeView 只选择单元格而不是行
- postgresql - Postgres 函数将 regexp_matches SETOF 结果转换为 ARRAY
- javascript - 检查用户的浏览器是否不支持javascript
- html - 显示的CSS交替行顺序:表
- c - 结构的大小取决于联合所在的位置
- android - 在模块番石榴错误中发现重复的类 com.google.common
- laravel - 如何查看评级为 1、3 和 5 Laravel 查询的所有记录
- vue.js - 我们可以改变 v-data-table 中选择菜单的样式(颜色)吗,默认 class primary--text 应用于高亮和标签
- r - 对多个列表中的多个变量进行统计测试(小标题)
- linux - 在拍摄照片之前调整网络摄像头设置(v4l2 和 fswebcam)