我正在rabbitmq-server v3.3.5-1.1
上运行Debian v8.2
。我根据docs中的建议启用了rabbitmq_web_stomp
和rabbitmq_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
答案 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…}