【问题标题】:read message from message queue in node.js从 node.js 中的消息队列中读取消息
【发布时间】:2021-03-11 14:04:34
【问题描述】:

我想连接到节点 js 中的活动消息队列 此代码正在连接队列,但问题是如何订阅特定队列?

   let ws = new WebSocket('ws://localhost:61614', 'stomp')

    ws.onopen = () => {
        console.log('opening...')
        ws.send('CONNECT\n\n\0')
    }

    ws.onclose = () => console.log('closing...')
    ws.onmessage = (e) => {
        if (e.data.startsWith('MESSAGE')) {
            console.log(e.data)
        }

    }

任何建议都会有所帮助,谢谢

【问题讨论】:

    标签: javascript node.js queue message-queue


    【解决方案1】:

    我已经解决了问题 问题出在这一行 startsWith('MESSAGE')) 应该是startsWith(''))

    【讨论】:

      【解决方案2】:

      根据Developer Mozilla documentation,没有“特定”队列。看看如何连接:

      // Create WebSocket connection.
      const socket = new WebSocket('ws://localhost:8080');
      
      // Connection opened
      socket.addEventListener('open', function (event) {
          socket.send('Hello Server!');
      });
      
      // Listen for messages
      socket.addEventListener('message', function (event) {
          console.log('Message from server ', event.data);
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-03-01
        • 2022-01-04
        • 2010-09-19
        • 2013-10-22
        • 1970-01-01
        • 2014-10-28
        • 2015-01-18
        相关资源
        最近更新 更多