ActiveMQ + NodeJS + Stomp 入门

风格不统一 提交于 2019-11-29 17:02:27

NodeJS + stomp-client 入门

准备

  • 下载ActiveMQ并安装

    1. 执行bin\win32\activemq.bat启动MQ服务
    2. 打开http://localhost:8161/admin/topics.jsp,其中用户名和密码都是 admin
  • npm安装stomp-client

npm install stomp-client --save

编写测试demo

demo.js

var Stomp = require('stomp-client');
    var destination = '/topic/myTopic';
    var client = new Stomp('127.0.0.1', 61613, 'user', 'pass');

    client.connect(function(sessionId) {
        client.subscribe(destination, function(body, headers) {
            console.log('This is the body of a message on the subscribed   queue:', body);
        });

        client.publish(destination, 'Jason Li');
    });

运行代码

node demo.js

打开http://localhost:8161/admin/send.jsp?JMSDestination=myTopic&JMSDestinationType=topic,你就可以看到从NodeJs发来的消息了。。

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!