前提
安装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窗口就可以看到刚才发送的消息
转载于:https://www.cnblogs.com/c-x-a/p/5458439.html
相关资源:JAVA上百实例源码以及开源项目