NodeJS + stomp-client 入门
准备
-
下载ActiveMQ并安装
- 执行bin\win32\activemq.bat启动MQ服务
- 打开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发来的消息了。。
来源:http://www.cnblogs.com/duhuo/p/5567438.html