RabbitMQ 和 web-stomp 的问题

Problems with RabbitMQ and web-stomp

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

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

但是,

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

  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, '/');

谢谢。

解决了,交易所名称需要"amq.topic"