zoukankan      html  css  js  c++  java
  • node(ActiveMq)

    简单尝试了node下的ActiveMQ

    1、下载apache-activemq-5.9.0,执行bat文件;

    2、登录http://localhost:8161/admin可查看其管理后台;

    3、安装stomp客户端 npm install stomp-client

    4、修改基础代码如下:

    var Stomp = require('stomp-client');
    var readline = require('readline');
    //创建两个不同的topic
    var topic1 = '/topic/topic1'; var topic2 = '/topic/topic2'; var rl = readline.createInterface({ input : process.stdin, output : process.stdout, terminal : false }); //1. publisher-subscribe 定义一个或者多个topic,然后给这些topic发送消息 //2. p2p 双方通过一个quene来发送、接收消息,一个quene只有一个发送、一个接收 //3. request-response 双方各有一个quene作为彼此的收发,相当于两个p2p var publisher = new Stomp('127.0.0.1', 61613, '', ''); //发布者 var subscriberA = new Stomp('127.0.0.1', 61613, '', ''); //订阅者A var subscriberB = new Stomp('127.0.0.1', 61613, '', ''); //订阅者B publisher.connect(function(sessionId) { rl.on('line', function(line) { switch (line.split(":")[0]) { case 'topic1': publisher.publish(topic1, line.split(":")[1]); break; case 'topic2': publisher.publish(topic2, line.split(":")[1]); break; default: console.log('commond error `' + line.trim() + '`'); break; } rl.prompt(); }).on('close', function() { console.log('close test project!'); process.exit(0); }); }); subscriberA.connect(function(sessionId) { subscriberA.subscribe(topic1, function(body, headers) { console.log('subscriberA From Topic1:', body); }); subscriberA.subscribe(topic2, function(body, headers) { console.log('subscriberA From Topic2:', body); }); }); subscriberB.connect(function(sessionId) { subscriberB.subscribe(topic1, function(body, headers) { console.log('subscriberB From Topic1:', body); }); subscriberB.subscribe(topic2, function(body, headers) { console.log('subscriberB From Topic2:', body); }); });

    输入不同命令后,控制台输出如下:

    同时在管理后台的topic栏目下,查看创建的topic

  • 相关阅读:
    DOM 与BOM
    尝试json文件导入数据
    js事件监听简介
    js事件简介
    js中的for语句简介
    作业练习正则表达式
    简单总结-BOM
    web前端第三次作业em,fr,rem,px简单解释及颜色表
    web第二次作业练习grid
    web前端课程第一次作业----注册页面代码(2018-9-14)
  • 原文地址:https://www.cnblogs.com/Fredric-2013/p/5783948.html
Copyright © 2011-2022 走看看