【发布时间】:2016-10-23 03:53:52
【问题描述】:
根据本教程,我在 Web 浏览器中使用 RabbitMQ 和 web-stomp: https://www.rabbitmq.com/web-stomp.htm
我成功连接并在浏览器中获取消息。
但是,
我在客户端发送和消费的消息还在队列中,没有出队(我做了手动确认和自动确认),它仍然存在。
当我订阅队列时,我没有收到队列中的所有消息,但只有最后一个.. 只有当 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