未找到RabbitMQ WebSocket 404

时间:2016-01-23 20:12:10

标签: nginx websocket rabbitmq cowboy

我正在rabbitmq-server v3.3.5-1.1上运行Debian v8.2。我根据docs中的建议启用了rabbitmq_web_stomprabbitmq_web_stomp_examples

rabbitmq-plugins enable rabbitmq_web_stomp
rabbitmq-plugins enable rabbitmq_web_stomp_examples

http://127.0.0.1:15670公开的所有示例都按预期工作,但它们都使用SockJS而非本机浏览器的WebSocket

// Stomp.js boilerplate
var ws = new SockJS('http://' + window.location.hostname + ':15674/stomp');
var client = Stomp.over(ws);

我想坚持WebSocket所以我尝试了文档中的建议:

var ws = new WebSocket('ws://127.0.0.1:15674/ws');

这会引起我的错误:

WebSocket connection to 'ws://127.0.0.1:15674/ws' failed: Error during WebSocket handshake: Unexpected response code: 404

netcat的进一步测试确认404

#  netcat -nv 127.0.0.1 15674
127.0.0.1 15674 open
GET /ws HTTP/1.1 
Host: 127.0.0.1

HTTP/1.1 404 Not Found
Connection: close
Content-Length: 0
Date: Sat, 23 Jan 2016 20:15:13 GMT
Server: Cowboy

显然cowboy没有公开/ws路径,所以我想知道:

  • 在这种情况下是否可以重新配置cowboy?怎么样?这值得么?
  • 我可以在nginx首选项)的位置使用cowboy吗?怎么样?
  • 我还有其他选择吗?

修改

RabbitMQ docs具有误导性。正确的WebSocket URI:

http://127.0.0.1:15674/stomp/websocket

1 个答案:

答案 0 :(得分:2)

干得好,但是:

  

新的WebSocket(' http://127.0.0.1:15674/stomp/websocket')

VM98:2 Uncaught DOMException: Failed to construct 'WebSocket': The URL's scheme must be either 'ws' or 'wss'. 'http' is not allowed.(…)(anonymous function) ...

需要使用ws / wss-schema:

  

新的WebSocket(' ws://127.0.0.1:15674 / stomp / websocket')

WebSocket {url: "ws://127.0.0.1:15674/stomp/websocket", readyState: 0, bufferedAmount: 0, onopen: null, onerror: null…}