【发布时间】:2016-01-18 17:10:42
【问题描述】:
我在 Tomcat8 上有一个 spring-websocket (4.1.6) 应用程序,它使用 STOMP RabbitMQ (3.4.4) 消息代理进行消息传递。当客户端 (Chrome 47) 启动应用程序时,它会订阅一个端点来创建一个持久队列。当此客户端从端点取消订阅时,队列将在 30 秒后由 RabbitMQ 清理,如定制的 RabbitMQ 策略中所定义。当我尝试重新连接到已清理队列的端点时,我在 RabbitMQ 日志中收到以下异常:“NOT_FOUND - vhost '/'\n 中没有队列 'position-updates-user9zm_szz9'”。我不想使用自动删除队列,因为我有一些重新连接逻辑,以防 websocket 连接中断。
可以通过在spring-websocket-portfolio github 示例中添加以下代码来重现此问题。
在index.html的容器div中添加:
<button class="btn" onclick="appModel.subscribe()">SUBSCRIBE</button>
<button class="btn" onclick="appModel.unsubscribe()">UNSUBSCRIBE</button>
在portfolio.js 中替换:
stompClient.subscribe("/user/queue/position-updates", function(message) {
与:
positionUpdates = stompClient.subscribe("/user/queue/position-updates", function(message) {
并添加以下内容:
self.unsubscribe = function() {
positionUpdates.unsubscribe();
}
self.subscribe = function() {
positionUpdates = stompClient.subscribe("/user/queue/position-updates", function(message) {
self.pushNotification("Position update " + message.body);
self.portfolio().updatePosition(JSON.parse(message.body));
});
}
现在您可以通过以下方式重现问题:
- 启动应用程序
- 点击退订
- 在 RabbitMQ 控制台中删除位置更新队列
- 点击订阅
通过 chrome devtools 和 RabbitMQ 日志在 websocket 框架中查找错误消息。
【问题讨论】:
标签: spring websocket rabbitmq stomp spring-websocket