2017-03-21 46 views
1

我正在使用webstomp与我的消息代理(本例中是兔子)进行通信。如何知道是否发送了一个stomp消息?

当我想要写一个消息我做到以下几点:由兔正确接收

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

此消息,但我想有一个方法来确认比viasually更多。类似于:

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

有没有办法做到这一点?

谢谢先进。

回答

1

消息可以可靠地从发布者传输到代理。 (使用交易或确认)。消息也可以可靠地从代理转移给消费者。 (使用确认) 综合起来,这提供了从发布者到消费者的可靠转移。

因此,在这种情况下,我要补充这个头:

{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(); 
相关问题