简体   繁体   English

RabbitMQ STOMP连接

[英]RabbitMQ STOMP connection

I am working on a fun project which requires me to learn message queues and websockets. 我正在做一个有趣的项目,需要我学习消息队列和websocket。 I am trying to connect browsers via websockets to an instance of rabbitmq using sockjs rather than pure websockets. 我正在尝试使用sockjs而非纯websockets通过websockets将浏览器连接到Rabbitmq实例。 On rabbit I have activated the plugins for stomp and web_stomp (web_stomp is required when using sockjs). 在Rabbit上,我已经激活了stomp和web_stomp插件(使用sockjs时需要web_stomp)。

The problem I am running into is that while the call from the browser seems to be working properly because a very brief connection to Rabbit is made through the webstomp/stomp connection but after 2 or 3 seconds the connection is dropped by Rabbit. 我遇到的问题是,来自浏览器的调用似乎正常工作,因为通过webstomp / stomp连接建立了与Rabbit的非常简短的连接,但是在2或3秒钟后Rabbit断开了该连接。

This is confirmed by the rabbitmq logs: 这由rabbitmq日志确认:

=INFO REPORT==== 11-Jul-2016::23:01:54 === accepting STOMP connection (192.168.1.10:49746 -> 192.168.1.100:55674) =信息报告==== 2016年7月11日::: 23:01:54 ===接受STOMP连接(192.168.1.10:49746-> 192.168.1.100:55674)
=INFO REPORT==== 11-Jul-2016::23:02:02 === closing STOMP connection (192.168.1.10:49746 -> 192.168.1.100:55674) =信息报告==== 2016年7月11日::: 23:02:02 ===关闭STOMP连接(192.168.1.10:49746-> 192.168.1.100:55674)

This is the browser code that connects to RabbitMQ via the webstomp plugin: 这是通过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));
  }
);

Here is the Rabbit config: 这是Rabbit配置:

[
    {rabbitmq_stomp, [{default_user, [{login, "test"},
                                    {passcode, "test"}
                                   ]
                    },
                    {tcp_listeners, [{"192.168.1.100", 55674}]},
                    {heartbeat, 0}
                   ]
    }
]

I have been over the Rabbit docs a million times but this feels like something simple that I am overlooking. 我已经看过一百万遍Rabbit文档,但这感觉就像是我忽略的简单事情。

Resolved. 解决。 After combing through the logs I realized that web_stomp was listening on port 15674 so I changed the config file to reflect that. 梳理日志后,我意识到web_stomp正在侦听端口15674,因此我更改了配置文件以反映该情况。 I swear I had made that change at some point but it did not seem to make a difference. 我发誓我已经在某个时候进行了更改,但似乎没有什么改变。

One of the late changes I made before sending out my request was to turn off heartbeat. 我在发出请求之前所做的最新更改之一是关闭心跳。 Everything I have read states that sockjs does not support heartbeat and that there were suggestions to turn it off rather than use the default. 我阅读的所有内容都指出sockjs不支持心跳,并且建议关闭它而不是使用默认值。 In addition to turning off heartbeat in the config file I also added this to the browser code: 除了在配置文件中关闭心跳之外,我还将其添加到浏览器代码中:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM