如何知道踩踏消息是否已正确发送



我正在使用webstomp与我的消息代理(在本例中为兔子(进行通信。

当我想写一条消息时,我会执行以下操作:

import * as SockJS from 'sockjs-client';
let client = Stomp.over(new SockJS(serverAddress));
client.connect(user, pass, onConnect, onError);
client.send('/exchange/amq.direct/test', {test: 'one', test2: 'two'});

兔子正确接收了此消息,但我希望有一种方法可以确认这一点。类似于:

client.send('/exchange/amq.direct/test', {test: 'one', test2: 'two'})
.then(() => {console.log('Message received correctly')})
.catch((err) => {console.log('Imposible send the message')})

有没有办法做到这一点?

消息可以可靠地从发布者传输到代理。(使用交易或确认(。消息也可以传输从经纪人到消费者的可靠。(使用致谢(总之,这提供了从发布商到消费者的可靠转移。

所以在这种情况下,我应该添加这个标题:

{persistent: true}

或者将事务用作:

// start the transaction
var tx = client.begin();
// send the message in a transaction
client.send("/queue/test", {transaction: tx.id}, "message in a transaction");
// commit the transaction to effectively send the message
tx.commit();

最新更新