如何从rabbitmq提供的webstomp websocket发送和接收数据?

时间:2016-06-15 07:39:02

标签: websocket rabbitmq stomp sockjs web-stomp

我正在编写一个没有显式服务器端Web套接字的聊天应用程序。 我使用RabbitMQ webstomp作为Web套接字容器和普通Javascript作为发送和接收数据的提示。

以下是流程: 浏览器 - > 原生websocket / sockjs - > rabbitmq / sockjs websocket ws://127.0.0.1:15674 / ws http://localhost:15674/stomp ) - >将消息放入队列。

然而,在测试应用程序时,我无法将数据直接发送到 ws://127.0.0.1:15674 / ws 。我只能连接到它。

我使用以下模板在客户端Javascript上发送和接收数据。

  1. ws = new WebSocket(' ws://127.0.0.1:15674 / ws');
  2. client = Stomp.over(ws);
  3. client.connect('旅客''客人',on_connection,on_connect_error,' /&#39);
  4. client.send(queue,{'回复':' / temp-queue / logs',优先级:9}," msg");
  5. client.onreceive = func()

1 个答案:

答案 0 :(得分:0)

问题很可能出现在您的代码中:

client.send(queue, {'reply-to':'/temp-queue/logs',priority: 9}, "msg" );

您必须将邮件发送到主题

我建议在此处查看示例:https://github.com/rabbitmq/rabbitmq-web-stomp-examples

以下是我为原始示例开始的一个快速示例:

var client = Stomp.client('ws://localhost:15674/ws');
      client.debug = pipe('#second');

      var print_first = pipe('#first', function(data) {
          client.send('/topic/test', {"content-type":"text/plain"}, data);
      });
      var on_connect = function(x) {
          id = client.subscribe("/topic/test", function(d) {
               print_first(d.body);
          });
      };
      var on_error =  function() {
        console.log('error');
      };
      client.connect('guest', 'guest', on_connect, on_error, '/');

enter image description here

相关问题