• 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

  • 相关阅读:
    mysql 修改字符集
    django 详细实例教程
    mysql 创建数据库
    Django 初始化数据库
    ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails
    2019 Multi-University Training Contest 1 D.Vacation(思维)
    2019牛客暑期多校训练营(第五场)E.independent set 1(状压dp)
    2019牛客暑期多校训练营(第三场)A.Graph Games (分块)
    2019牛客暑期多校训练营(第五场)I.three points 1(暴力几何)
    2019牛客暑期多校训练营(第五场)H.subsequence 2(拓扑)
  • 原文地址:https://www.cnblogs.com/Fredric-2013/p/5783948.html
Copyright © 2020-2023  润新知