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窗體就能夠看到剛才發送的消息


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM