我正在尝试接收来自RabbitMq-Que和Stomp-plugin的消息。这工作得很好,但问题是我会从队列中获取每条消息。因此,如果队列有13条消息,我会得到13条消息。关键是我只想得到1条消息,并在发送Ack或Nack之后获得下一条消息。有人知道如何只收到一条消息吗?谢谢你的帮助。
下面是我得到的代码:
GetMessage()
{
this.GetRabbitMqClient().then((client)=>
{
var headers ={ack:'client', 'x-max-priority': '10'};
var subscription = client.subscribe("/queue/TestQue",this.messageCallback,headers);
});
}
private messageCallback = function(Message :IMessage)
{
console.log(Message.body);
setTimeout(()=> {Message.ack();},100000000000000);
}
private GetRabbitMqClient( ):Promise<Client> {
var promise = new Promise<Client>((resolve,reject)=>{
var client = new Client(
{
brokerURL: "ws://localhost:15674/ws",
connectHeaders:
{
login: "guest",
passcode: "guest"
},
// debug: function (str) {
// console.log(str);
// },
reconnectDelay: 5000,
heartbeatIncoming: 4000,
heartbeatOutgoing: 4000
});
client.onConnect = function (frame) {
resolve(client);
};
client.onStompError = function (frame) {
// Will be invoked in case of error encountered at Broker
// Bad login/passcode typically will cause an error
// Complaint brokers will set `message` header with a brief message. Body may contain details.
// Compliant brokers will terminate the connection after any error
reject(frame);
console.log('Broker reported error: ' + frame.headers['message']);
console.log('Additional details: ' + frame.body);
};
client.activate();
});
return promise;
}发布于 2019-01-21 21:22:59
我找到了解决方案:你只需要在头文件中设置属性:'prefetch-count':'1‘
https://stackoverflow.com/questions/54290253
复制相似问题