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/