2016-07-12 120 views
0

我正在开发一个有趣的项目,它需要我学习消息队列和websockets。我试图通过websockets将浏览器连接到使用sockjs而不是纯websocket的rabbitmq实例。在兔子我已经激活了stomp和web_stomp插件(使用sockjs时需要web_stomp)。RabbitMQ STOMP连接

我遇到的问题是,虽然来自浏览器的呼叫似乎正常工作,因为通过webstomp/stomp连接与兔子进行非常简短的连接,但在2或3秒后,连接被兔子。

这由RabbitMQ的日志证实:

= INFO REPORT ==== 11-JUL-2016 :: 23:01:54 === 接受STOMP连接(192.168.1.10:49746 - > 192.168.1.100:55674)
= INFO REPORT ==== 2016年7月11日:: 23:02:02 === 正在关闭STOMP连接(192.168.1.10:49746 - > 192.168.1.100:55674)

这是通过webstomp插件连接到RabbitMQ的浏览器代码:
var url = "http://192.168.1.100:55674/stomp"; var ws = new SockJS(url); var client = Stomp.over(ws); var header = { login: 'test', passcode: 'test' }; client.connect(header, function(){ console.log('Hooray! Connected'); }, function(error){ console.log('Error connecting to WS via stomp:' + JSON.stringify(error)); } );

这里是兔子的配置: [ {rabbitmq_stomp, [{default_user, [{login, "test"}, {passcode, "test"} ] }, {tcp_listeners, [{"192.168.1.100", 55674}]}, {heartbeat, 0} ] } ]. 我一直在兔年文档一百万次,但这种感觉就像简单的东西,我俯瞰。

回答

0

已解决。在梳理日志之后,我意识到web_stomp正在侦听端口15674,所以我更改了配置文件以反映这一点。我发誓我曾在某个时候做过这种改变,但似乎没有什么区别。

在发送我的请求之前,我做出的最近更改之一是关闭心跳。我读过的一切都表明,sockjs不支持心跳,并且有建议将其关闭,而不是使用默认值。除了关闭配置文件中的心跳信号之外,我还将此添加到浏览器代码中:

client.heartbeat.outgoing=0; 
client.heartbeat.incoming=0;