zoukankan      html  css  js  c++  java
  • 试用solace 消息平台

    solace 是一个很不错的消息pubsub 平台,以下是一个简单的试用

    启动

    docker run -d -p 8080:8080 -p 55555:55555 -p:8008:8008 -p:1883:1883 -p:8000:8000 -p:5672:5672 -p:9000:9000 -p:2222:2222 --shm-size=2g --env username_admin_globalaccesslevel=admin --env username_admin_password=admin --name=solace solace/solace-pubsub-standard

    端口说明

    port 8080 — Use this port when configuring the message broker container with Solace PubSub+ Manager.
    port 55555 — Your applications can use Solace APIs to connect to the message broker on this port.
    port 8008 — The JavaScript sample applications below use this port to pass Web Messaging traffic through the message broker.
    ports 1883 & 8000 — Ports for MQTT connectivity, over TCP and over WebSockets respectively
    port 5672 — AMQP 1.0 applications using Apache QPID APIs would connect here
    port 9000 — Use REST to send messaging and event data with Solace’s RESTful API port
    port 2222 — Use SSH to connect to the Solace Command Line Interface (CLI) for advanced configuration

    试用

    测试下share subscription,

    • package.json
     
    {
      "name": "client",
      "version": "1.0.0",
      "main": "index.js",
      "license": "MIT",
      "dependencies": {
        "mqtt": "^4.2.6"
      },
      "scripts": {
        "app:app1": "node app.js",
        "app:app2":"node app2.js",
        "run-all":"npm-run-all --parallel app:**"
      },
      "devDependencies": {
        "npm-run-all": "^4.1.5"
      }
    }
    • app.js && app2.json
      app.js
     
    var mqtt = require('mqtt')
    var client  = mqtt.connect('mqtt://127.0.0.1')
    client.on('connect', function () {
      client.subscribe('$share/service1/dalongdemo', function (err) {
        if (!err) {
          client.publish('presence', 'Hello mqtt')
        }
      })
    })
    client.on('message', function (topic, message) {
      // message is Buffer
      console.log("app1")
      console.log(message.toString())
    })
     
     

    app2.js

    var mqtt = require('mqtt')
    var client  = mqtt.connect('mqtt://127.0.0.1')
    client.on('connect', function () {
      client.subscribe('$share/service1/dalongdemo', function (err) {
        if (!err) {
          client.publish('presence', 'Hello mqtt')
        }
      })
    })
    client.on('message', function (topic, message) {
      // message is Buffer
      console.log("app2")
      console.log(message.toString())
    })
    • 运行
    yarn run-all
    • 发布消息


    效果

    参考资料

    https://solace.com/products/event-broker/software/getting-started/

  • 相关阅读:
    结对编程2
    结对编程总结:简单的四则运算生成程序
    我的结对项目心得与代码规范
    一个团队和他们的调查表-----("调查表与调查结果分析"心得体会)
    目标?我定好了!(我的软件工程课目标)
    Jmeter响应数据为乱码的处理
    软件工程课程建议
    结对编程之Fault、Error、Failure
    我的结对项目编程感想
    调查问卷后的心得
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/14063645.html
Copyright © 2011-2022 走看看