【问题标题】:Problems with RabbitMQ and web-stompRabbitMQ 和 web-stomp 的问题
【发布时间】:2016-10-23 03:53:52
【问题描述】:

根据本教程,我在 Web 浏览器中使用 RabbitMQ 和 web-stomp: https://www.rabbitmq.com/web-stomp.htm

我成功连接并在浏览器中获取消息。

但是,

  1. 我在客户端发送和消费的消息还在队列中,没有出队(我做了手动确认和自动确认),它仍然存在。

  2. 当我订阅队列时,我没有收到队列中的所有消息,但只有最后一个.. 只有当 websocket 打开然后服务器发送消息时,我才收到最后一条消息但没有旧的。

服务器代码:

private static final String EXCHANGE_NAME = "amq.topic";

public static void AddToQueue(String RoutingKey, String message) throws IOException, TimeoutException {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("localhost");
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();

    channel.exchangeDeclare(EXCHANGE_NAME, "topic");

        channel.basicPublish(EXCHANGE_NAME, RoutingKey, null, message.getBytes());

        channel.close();
        connection.close();
}

客户端代码:

 var ws = new SockJS('http://' + window.location.hostname + ':15674/stomp');
$scope.client = Stomp.over(ws);
$scope.client.heartbeat.outgoing = 0;
$scope.client.heartbeat.incoming = 0;
var on_connect = function(x) {
       $scope.client.subscribe("/topic/status", function(d) {
           console.log(d.body);
});
};
var on_error =  function() {
    console.log('error');
};
$scope.client.connect('guest', 'guest', on_connect, on_error, '/');

谢谢。

【问题讨论】:

    标签: javascript rabbitmq stomp web-stomp


    【解决方案1】:

    解决了,交易所名称需要是“amq.topic”

    【讨论】:

    • 5 个月后回答这个问题做得很好。非常手提包。
    猜你喜欢
    • 2016-11-15
    • 2018-11-22
    • 1970-01-01
    • 2015-05-26
    • 1970-01-01
    • 1970-01-01
    • 2019-05-08
    • 1970-01-01
    • 2012-09-16
    相关资源
    最近更新 更多