feuyeux / hello-mqtt

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hello MQTT

hello-mqtt

paho

1 Start Broker

brew install mosquitto
sh start_mosquito.sh
brew install emqx
emqx start
$ emqx ctl status

Node 'emqx@127.0.0.1' 5.3.2 is started
emqx stop

http://localhost:18083/ The default user name and password are admin & public

API 密钥 设置API KeySecret Key

ak:9b71d224bd62f378 sk:mz0kFjgqbHPTUTAiBFcoY4rbmIsD3QXwJbaKQcNErlI

HTTP API

curl -i \
-u 9b71d224bd62f378:mz0kFjgqbHPTUTAiBFcoY4rbmIsD3QXwJbaKQcNErlI \
"http://localhost:18083/api/v5/nodes"

curl -i \
-u 9b71d224bd62f378:mz0kFjgqbHPTUTAiBFcoY4rbmIsD3QXwJbaKQcNErlI \
"http://localhost:18083/api/v5/topics"

curl -i \
-u 9b71d224bd62f378:mz0kFjgqbHPTUTAiBFcoY4rbmIsD3QXwJbaKQcNErlI \
"http://localhost:18083/api/v5/trace"

http://localhost:18083/api-docs/index.html#/Publish/post_publish

curl -i \
-u 9b71d224bd62f378:mz0kFjgqbHPTUTAiBFcoY4rbmIsD3QXwJbaKQcNErlI \
-X 'POST' \
  'http://localhost:18083/api/v5/publish' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "topic": "mqtt/test",
  "payload": "hello emqx api"
}'

http://localhost:18083/api-docs/index.html#/Clients/post_clients__clientid__subscribe

curl -i \
    -u 9b71d224bd62f378:mz0kFjgqbHPTUTAiBFcoY4rbmIsD3QXwJbaKQcNErlI \
    -X 'POST' \
    "http://localhost:18083/api/v5/clients/java_publish_client/subscribe" \
    -H 'accept: application/json' \
    -H 'Content-Type: application/json' \
    -d '{
   "topic": "mqtt/test"
}'

https://www.emqx.io/docs/zh/latest/deploy/upgrade-from-v4.html#http-api

2 Build Client

使用emqx实验时,确保http://localhost:18083/#/authentication页面中没有配置

hello-mqtt-java build

build.sh

mvn clean install -DskipTests

hello-mqtt-rust build

cargo build

hello-mqtt-go build

go env -w GOPROXY=https://goproxy.cn,direct
go get github.com/eclipse/paho.mqtt.golang
go build

3 Run Client

hello-mqtt-java run

service

start_service.sh

cd mqtt-service 
mvn spring-boot:run 

look_up.sh

curl http://localhost:8080/temps/stats

sensor

start_sensor.sh

cd mqtt-sensor 
mvn spring-boot:run 

hello-mqtt-rust run

sub

cargo run --bin sub

pub

cargo run --bin pub

hello-mqtt-go run

go run main.go

Reference

About


Languages

Language:Java 86.9%Language:Rust 8.4%Language:Go 2.7%Language:Shell 2.0%