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