MQTT学习(六)–各类MQTT代理服务器特性对比(译文)_lordwish的专栏-CSDN博客https://blog.csdn.net/lordwish/article/details/85061687
5G 时代,万物互联消息引擎 | 全球领先的开源 MQTT 消息服务器 | EMQhttps://www.emqx.io/cn/
程序安装 (Installation) — EMQ X - 百万级开源 MQTT 消息服务器 3.2.0 文档https://docs.emqx.io/broker/v3/cn/install.html
使用指南 · EMQ X Tutorialhttps://docs.emqx.io/tutorial/v3/cn/
Installing via EMQ X Docker Image
docker run -d --name emqx -p 1883:1883 -p 8083:8083 -p 8883:8883 -p 8084:8084 -p 18083:18083 emqx/emqx
访问EMQT web管理页面:
http://ip:18083 默认账号:admin 密码:public
Python使用mqtt极简例子
https://www.jianshu.com/p/0ed4e59b1e8f
推数据 pub.py
#!/usr/bin/env python
import paho.mqtt.client as mqtt
def on_connect(client, userdata, flags, rc):
print("Connected with result code: " + str(rc))
def on_message(client, userdata, msg):
print(msg.topic + " " + str(msg.payload))
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect(‘10.110.149.132’, 1883, 600) # 600为keepalive的时间间隔
client.publish(‘fifa’, payload=‘amazing’, qos=0)
阻塞接收数据sub.py
#!/usr/bin/env python
import paho.mqtt.client as mqtt
def on_connect(client, userdata, flags, rc):
print("Connected with result code: " + str(rc))
def on_message(client, userdata, msg):
print(msg.topic + " " + str(msg.payload))
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect(‘10.110.149.132’, 1883, 600) # 600为keepalive的时间间隔
client.subscribe(‘fifa’, qos=0)
client.loop_forever() # 保持连接
先运行sub.py 在运行pub.py 就能收到数据
EMQX的个人空间 - OSCHINAhttps://my.oschina.net/u/4174826
kerl build 22.0 erlang22.0
EMQX 规则引擎 简单实现将8266消息保存到MySQL数据库以及更新数据_weixin_44821644的博客-CSDN博客https://blog.csdn.net/weixin_44821644/article/details/100593769
方法一
yum -y install make
yum -y install gcc
yum -y install gcc-c++
yum -y install kernel-devel
yum -y install m4
yum -y install ncurses-devel
yum -y install openssl-devel
yum -y install rsync
yum -y install perl-net-snmp
yum -y install wx
yum -y install fop
yum -y install net-snmp
yum -y install unixODBC
yum -y install unixODBC-devel
yum -y install lrzsz
yum -y install bc
yum -y install sysstat
yum -y install lsof
yum -y install wget
yum -y install xz
yum -y install automake
yum -y install autoconf
安装Erlang报错
https://www.cnblogs.com/tu6ge/p/5673320.html
方法二
安装Erlang/OTP的简单方法 - 简书
https://www.jianshu.com/p/caddaa8251af
curl -O https://raw.githubusercontent.com/yrashk/kerl/master/kerl
chmod a+x kerl
kerl build 22.0 erlang22.0
kerl install erlang22.0 /home/Erlang22_0
. /home/home/Erlang22_0/activate
ln -s /home/Erlang22_0/bin/erl /usr/local/bin/
EMQ扩展插件-emq_plugin_kafka - 简书https://www.jianshu.com/p/1e3bfd383280
EMQ集成Kafka插件编写过程 emq_plugin_kafka_caijiapeng0102的博客-CSDN博客https://blog.csdn.net/caijiapeng0102/article/details/80852933
【跟我一起搭建物联网平台】6、EMQX之Kafka插件编译安装http://www.piaoyi.org/iot/635.html
BerkOzdilek/emq_kafka-bridge_docker: emqtt with redis auth plugin, kafka bridgehttps://github.com/BerkOzdilek/emq_kafka-bridge_docker
物联网架构成长之路(8)-EMQ-Hook了解、连接Kafka发送消息_weixin_34112030的博客-CSDN博客https://blog.csdn.net/weixin_34112030/article/details/85963541
python 订阅消息通知
#!/usr/bin/env python
import paho.mqtt.client as mqtt
import json
import time
HOST = “10.110.149.130”
PORT = 1883
client_id = “1083421130” # 没有就不写,此处部分内容用xxx代替原内容,下同
def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
client.subscribe(“data/receive”) # 订阅消息
def on_message(client, userdata, msg):
print(“主题:”+msg.topic+" 消息:"+str(msg.payload.decode(‘utf-8’)))
def on_subscribe(client, userdata, mid, granted_qos):
print(“On Subscribed: qos = %d” % granted_qos)
def on_disconnect(client, userdata, rc):
if rc != 0:
print(“Unexpected disconnection %s” % rc)
data = {
“type”:2,
“timestamp”: time.time(),
“messageId”:“9fcda359-89f5-4933-xxxx”,
“command”:“130/recommend”,
“data”:{
“openId”:“130”,
“appId”:130,
“recommendType”:“temRecommend”
}
}
param = json.dumps(data)
client = mqtt.Client(client_id)
client.username_pw_set(“xxxxxx”, “xxxxxx”)
client.on_connect = on_connect
client.on_message = on_message
client.on_subscribe = on_subscribe
client.on_disconnect = on_disconnect
client.connect(HOST, PORT, 60)
client.publish(“data/send”, payload=param, qos=0) # 发送消息
client.loop_forever()
go编写mqtt 连接和发布消息示例
https://www.jianshu.com/p/0ad7582baa93
package main
import (
“flag”
“fmt”
mqtt “github.com/eclipse/paho.mqtt.golang”
“sync”
“time”
)
/***
*
//客户端连接判断
if token := client.Connect(); token.WaitTimeout(time.Duration(60)*time.Second) && token.Wait() && token.Error() != nil {
failNums++
fmt.Printf("[Pub] mqtt connect error, taskId: %d, fail_nums: %d, error: %s \n", taskId, failNums, token.Error())
return
}
i := 0
for {
i++
time.Sleep(time.Duration(3) * time.Second)
text := fmt.Sprintf(“this is test msg #%d ! from task :%d”, i, taskId)
//fmt.Printf(“start publish msg to mqtt broker, taskId: %d, count: %d \n”, taskId, i)
//发布消息
token := client.Publish(“go-test-topic”, 1, false, text)
fmt.Printf("[Pub] end publish msg to mqtt broker, taskId: %d, count: %d, token : %s \n", taskId, i, token)
token.Wait()
}
client.Disconnect(250)
fmt.Println("[Pub] task is ok")
}
/***
*
//客户端连接判断
if token := client.Connect(); token.WaitTimeout(time.Duration(60)*time.Second) && token.Wait() && token.Error() != nil {
failNums++
fmt.Printf("[Sub] mqtt connect error, taskId: %d, fail_nums: %d, error: %s \n", taskId, failNums, token.Error())
return
}
i := 0
for {
i++
time.Sleep(time.Duration(3) * time.Second)
//fmt.Printf(“start publish msg to mqtt broker, taskId: %d, count: %d \n”, taskId, i)
//发布消息
token := client.Subscribe(“go-test-topic”, 1, messageSubHandler)
fmt.Printf("[Sub] end Subscribe msg to mqtt broker, taskId: %d, count: %d, token : %s \n", taskId, i, token)
token.Wait()
}
client.Disconnect(250)
fmt.Println("[Sub] task is ok")
}
//创建全局mqtt publish消息处理 handler
var messagePubHandler mqtt.MessageHandler = func(client mqtt.Client, msg mqtt.Message) {
fmt.Printf(“Pub Client Topic : %s \n”, msg.Topic())
fmt.Printf(“Pub Client msg : %s \n”, msg.Payload())
}
//创建全局mqtt sub消息处理 handler
var messageSubHandler mqtt.MessageHandler = func(client mqtt.Client, msg mqtt.Message) {
fmt.Printf(“Sub Client Topic : %s \n”, msg.Topic())
fmt.Printf(“Sub Client msg : %s \n”, msg.Payload())
}
//连接失败数
var failNums = 0
/***
for i := 0; i < nums; i++ {
fmt.Printf(“publish client num : %s \n”, i)
waitGroup.Add(1)
time.Sleep(3 * time.Millisecond)
//调用连接和发布消息
go mqttConnPubMsgTask(i, &waitGroup)
//订阅
go mqttConnSubMsgTask(i, &waitGroup)
}
waitGroup.Wait()
}