【问题标题】:RabbitMQ WebSocket 404 Not FoundRabbitMQ WebSocket 404 未找到
【发布时间】:2016-01-23 20:12:09
【问题描述】:

我在Debian v8.2 上运行rabbitmq-server v3.3.5-1.1。根据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

【问题讨论】:

    标签: nginx websocket rabbitmq cowboy


    【解决方案1】:

    干得好,但是:

    新的 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…}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-16
      • 2021-07-14
      • 1970-01-01
      • 1970-01-01
      • 2011-04-17
      • 2021-03-21
      • 2017-04-04
      • 2016-10-06
      相关资源
      最近更新 更多