2018-08-16

EMQ/emqttd (Erlang MQTT Broker)

EMQ (Erlang MQTT Broker) is a distributed, massively scalable, highly extensible MQTT message broker written in Erlang/OTP.

在 openSUSE 從 source code 安裝,需要下列的套件:
sudo zypper in erlang erlang-observer

(erlang/otp version 需要 >= R17)

再來是下載 source code 並且編譯:
git clone https://github.com/emqtt/emq-relx.git
cd emq-relx && make

如果要執行的話:
cd _rel/emqttd && ./bin/emqttd console


再來使用 tcl.mqttc 驗證是否可以正確連線,這只是進行簡單的驗證。
Subscribe:
package require mqttc

mqttc client "tcp://localhost:1883" "USERSSub" 1 -cleansession 1 
client subscribe  "MQTT Examples" 1
while 1 {
    if {[catch {set result [client  receive]}]} {
        puts "Receive error!!!"
        break
    }
    if {[llength $result] > 0} {
        puts "[lindex $result 0] - [lindex $result 1]"
        if {![string compare -nocase [lindex $result 1] "Exit"]} {
            break
        }
    }
}
client unsubscribe  "MQTT Examples"
client close

Publish:
package require mqttc

mqttc client "tcp://localhost:1883" "USERSPub" 1 -timeout 1000
client publishMessage "MQTT Examples" "Hello MQTT!" 1 0
client publishMessage "MQTT Examples" "Exit" 1 0
client close

先執行 Subscribe 的部份,再使用 Publish 發送訊息,確定可以正確執行。

沒有留言: