概要
Pub-Sub型の双方向通信を実現してくれるプロトコルです。
環境
- Ubuntu 14.04
- Mosquitto 0.15
- MQTT 3.1
用語
名称 | 役割 |
---|---|
Broker | サーバ |
Publisher | クライアント。データの送信側 |
Subscriber | クライアント。データの受信側 |
Topic | メッセージをやりとりするチャンネル名 |
今回は1台で上記を構築します。
インストール
サーバ
$ sudo apt-get install mosquitto
インストールしたらサービスとして自動起動してます
$ sudo service mosquitto status mosquitto start/running, process 2829
クライアント
$ sudo apt-get install mosquitto-clients
動作確認
トピック名をhello
としてSubscribeします。
$ mosquitto_sub -d -t hello Received CONNACK Received SUBACK Subscribed (mid: 1): 0
別ターミナルでPublishします。同じトピック名hello
を指定してメッセージを付けます。
$ mosquitto_pub -d -t hello -m "hello world" Received CONNACK Sending PUBLISH (d0, q0, r0, m1, 'hello', ... (11 bytes))
するとSubscribeの方で受信が確認できます。
Received PUBLISH (d0, q0, r0, m0, 'hello', ... (11 bytes)) hello world