wiki:MQTT

Version 5 (modified by krit, 4 years ago) (diff)

--

MQTT

Create 3 folders and 3 config files as following

[krit@mini MQTT]$ tree .
.
└── mosquitto
    ├── config
    │   ├── acls.conf
    │   ├── mosquitto.conf
    │   └── passwd
    ├── data
    └── log

4 directories, 3 files
[krit@mini MQTT]$ 

In mosquitto.conf, we put following config

[krit@mini MQTT]$ cat mosquitto/config/mosquitto.conf 
# following two lines required for > v2.0
#allow_anonymous true
listener 1883
persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log

allow_anonymous false
password_file /mosquitto/config/passwd
acl_file /mosquitto/config/acls.conf

We create user 'alice' for Mqtt broker with command

[krit@mini MQTT]$ mosquitto_passwd ./mosquitto/config/passwd alice

With ACL (Access Control List), we allow user to pub/sub to specific topic by

[krit@mini MQTT]$ cat mosquitto/config/acls.conf 

user admin
topic #

user alice
topic readwrite cat/#

user bob
topic read  gw/+/status/#
topic write gw/+/cmd/#

Then, we can run mosquitto with following

[krit@mini MQTT]$ docker run -it --name mosquitto -p 1883:1883 -v $(pwd)/mosquitto:/mosquitto/ eclipse-mosquitto

Attachments (2)

Download all attachments as: .zip