Mac下使用 mqtt記錄

1,首先安裝
brew install mosquitto

2,安裝之後,有點機器回無法link,出現這種情況試試如下方法:

for someone who got error when running brew link

Linking /usr/local/Cellar/ç/1.5.4_1...

Error: Could not symlink sbin/mosquitto

/usr/local/sbin is not writable.

try this:

  sudo mkdir -p /usr/local/sbin

  sudo chown -R $(whoami) /usr/local/sbin

3,啓動

/usr/local/opt/mosquitto/sbin/mosquitto -c /usr/local/etc/mosquitto/mosquitto.conf

4,訂閱,發送消息

mosquitto_pub -t 'test/topic' -m 'hello world'

mosquitto_sub -t 'test/topic' -v

鏈接:https://www.jianshu.com/p/538401850d1a
 

以上是我在搭建mqtt服務器時參照的資料,開啓服務器之後,最後訂閱服務器的時候,老是出現找不到命令的情況,後面發現需要進入到mqtt的命令路徑下才能使用命令,我的mosquitto命令路徑是這個: /usr/local/opt/mosquitto/bin/ 進入這個路徑之後 訂閱topic的命令做了一點點修改,不知道其他需要使用mosquitto的朋友會不會也是這樣,
訂閱的指令修改成:./mosquitto_sub -t 'test/topic' -v 
'test/topic' 這個是我的topic
發送消息指令:  ./mosquitto_pub -t 'test/topic' -m 'get a new staff face'

'get a new staff face' 這個是消息內容;
沒有使用mqtt的客戶端,直接用終端開啓服務器,訂閱,發送消息

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章