简体   繁体   English

如何知道 stomp 消息是否已正确发送?

[英]How to know if a stomp message have been send correctly?

I am using webstomp to comunicate with my message broker (In this case rabbit).我正在使用 webstomp 与我的消息代理(在本例中为兔子)进行通信。

When I want to write a message I do the following:当我想写一条消息时,我会执行以下操作:

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'});

This message is received correctly by Rabbit but I would like to have a way to confirm that more than viasually. Rabbit 正确接收到此消息,但我希望有一种方法来确认这一点,而不是通过口头方式。 Something similar to:类似于:

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

Is there a way to do this?有没有办法做到这一点?

Messages can be transferred reliably from publishers to the broker.消息可以可靠地从发布者传输到代理。 (using transactions or confirms). (使用交易或确认)。 Messages can also be transferred reliably from the broker to consumers.消息也可以从代理可靠地传输到消费者。 (using acknowledgements) Taken together this provides reliable transfer from publishers to consumers. (使用确认)总之,这提供了从发布者到消费者的可靠传输。

So in this case I should add this header:所以在这种情况下,我应该添加这个标题:

{persistent: true}

Or use a transaction as:或将事务用作:

// 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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM