前提
安裝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中運行
就能夠看到從NodeJs發來的消息
6.在上述頁面的Text Message窗體輸入幾個字符串,點擊Send
在NodeJS窗體就能夠看到剛才發送的消息