๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

OS/๐Ÿง Linux

๐Ÿง Ubuntu * mosquitto, mosquitto-client ์„ค์น˜ํ•˜๊ธฐ

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