【问题标题】:How to know if a stomp message have been send correctly?¿如何知道是否已正确发送单脚消息?¿
【发布时间】:2017-08-12 23:42:52
【问题描述】:

我正在使用 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'});

Rabbit 正确接收到此消息,但我希望通过一种方式来确认这一点,而不是通过口耳相传。类似于:

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

有没有办法做到这一点?

提前致谢。

【问题讨论】:

    标签: javascript rabbitmq stomp sockjs web-stomp


    【解决方案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();
    

    【讨论】:

      猜你喜欢
      • 2020-10-24
      • 1970-01-01
      • 2012-06-28
      • 2023-03-20
      • 2013-08-19
      • 2019-05-31
      • 1970-01-01
      • 2016-04-24
      • 2012-02-03
      相关资源
      最近更新 更多