OS/๐ง Linux
๐ง Ubuntu * mosquitto, mosquitto-client ์ค์นํ๊ธฐ
___l_i_ *
2020. 3. 9. 16:35
2019/08/09 ๊ธฐ์ค Mosquitto์์ snap ์ปค๋งจ๋๋ฅผ ์ง์ํ๋ค.
๋ช ๋ น์ด๋ฅผ ์ฐ๋ฉด ํจ์ฌ ๊ฐํธํ๊ฒ ์ค์นํ ์ ์๋ค.
Broker (mosquitto-server) ์ค์น
1. ์ ์ฅ์๋ฅผ ์ด์ฉํ Broker Server ์ค์น
A. ์ ์ฅ์ ์ ๋ฐ์ดํธ
$ sudo apt-get install python3-software-properties
$ sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa
$ sudo apt-get update
B. ์ ์ฅ์ ์ ๋ฐ์ดํธ ํ์ธ
$ sudo apt-cache search mosquitto
C. Mosquitto server ์ค์น
$ sudo apt-get install mosquitto
D. ์ค์น ํ์ธ
$ mosquitto
2. Snap ์ปค๋งจ๋๋ฅผ ์ด์ฉํ Broker (mosquitto-server) ์ค์น
์ปค๋งจ๋๋ฅผ ์ฌ์ฉํ ์ค์น๋ ํด๋ณด์ง ์์๋ค.
$ snap install mosquitto
Mosquitto-Client ์ค์น
Client ์ค์น๋ ๋งค์ฐ ๊ฐ๋จํ๋ค. ์์ ์ ์ฅ์๋ฅผ ๋ฑ๋กํด์ ๊ทธ๋ฐ ๊ฒ์ธ์ง ๋ชจ๋ฅด๊ฒ ์ง๋ง...
๋ค์ ๋ช ๋ น์ด ํ ์ค์ด๋ฉด ์ค์น๊ฐ ๊ฐ๋ฅํ๋ค.
$ sudo apt-get install mosquitto-clients
Subscribe์ Publish ๋์ ํ์ธํ๊ธฐ
์ต์ ์ -d๊ฐ ๋ค์ด๊ฐ ๊ฒ์ ๋๋ฒ๊ทธ ๋ฉ์์ง๋ฅผ ์ฌ์ฉํ๋ค๋ ๊ฒ์ธ๋ฐ, ๊ตณ์ด ์ฌ์ฉํ์ง ์์๋ ๋๋ค.
A. Subscribe ์ค์
Topic: hello/world
$ mosquitto_sub -d -t hello/world
B. Publish ์ค์
hello/world ๊ตฌ๋ ์ 2๋ช
$ mosquitto_pub -d -t hello/world -m "Hi, I am Leni"
- hello/leni ๊ตฌ๋ ์ 1๋ช
$ mosquitto_pub -d -t hello/leni -m "hi? leni?"
C. ์คํ ๊ฒฐ๊ณผ
์ฌ์ง์ด ์ ๋ณด์ด์ง ์๋ ๊ฒฝ์ฐ ํด๋ฆญํ๋ฉด ์๋ณธํฌ๊ธฐ๋ก ๋ณผ ์ ์์ต๋๋ค :)
Thanks for