ActiveMQ + NodeJS + Stomp 极简入门

前提

安装ActiveMQ和Nodejs

測试步骤

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

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

username和password都是 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窗体就能够看到刚才发送的消息