ActiveMQ + NodeJS + Stomp 极简入门

穿精又带淫゛_ 提交于 2019-11-29 17:03:52

前提

 安装ActiveMQ和Nodejs

 

测试步骤

1.执行bin\win32\activemq.bat启动MQ服务

2. 打开http://localhost:8161/admin/topics.jsp

用户名和密码都是 admin

3. 下载Stomp

 

npm install stomp-client

4. 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('From MQ:', body);
    });

    client.publish(destination, 'Hello World!');
});

 

 

在NodeJS中执行

 

5. 打开http://localhost:8161/admin/send.jsp?JMSDestination=myTopic&JMSDestinationType=topic

就可以看到从NodeJs发来的消息

 

6.在上述页面的Text Message窗口输入几个字符串,点击Send

在NodeJS窗口就可以看到刚才发送的消息

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