MQTT大杂烩

栏目: 后端 · 发布时间: 6年前

内容简介:MQTT是一套标准,常用的服务端有Eclipse的Mosquitto。MQTT是IBM出品,Eclipse也是IBM出品,所以Mosquitto算是官方实现吧。执行命令启动:

MQTT是一套标准,常用的服务端有Eclipse的Mosquitto。MQTT是IBM出品,Eclipse也是IBM出品,所以Mosquitto算是官方实现吧。

Mosquitto在macOS下的安装

执行命令 brew install mosquitto 即可安装

启动:

  • 理论上 brew services start mosquitto 可以启动,但是我这边启动不了,也找不到报错信息和相关日志。所以放弃
  • 手动启动: /usr/local/opt/mosquitto/sbin/mosquitto -c /usr/local/etc/mosquitto/mosquitto.conf -v 以Verbose模式阻塞式启动。也可以不使用 -c 选项,用默认配置启动Mosquitto

Mosquitto启动日志:

1543540708: mosquitto version 1.5.4 starting
1543540708: Config loaded from /usr/local/etc/mosquitto/mosquitto.conf.
1543540708: Opening ipv6 listen socket on port 1883.
1543540708: Opening ipv4 listen socket on port 1883.

可见Mosquitto默认监听1883端口

MQTT演示

MQTT是一套消息订阅与发布协议,这里我启动一个客户端订阅与监听 animal 主题,然后用另一个客户端向 animal 主题发送消息。控制台输出如下如下:

消息发布端

$ mosquitto_pub --topic animal --message "ant"

$ mosquitto_pub --topic animal --message "bee"

消息发布端没有控制台输出,发布消息后直接退出

消息订阅端

$ mosquitto_sub --topic animal

ant
bee

服务端

1543542192: New connection from ::1 on port 1883.
1543542192: New client connected from ::1 as mosqsub|73254-MacBook-A (c1, k60).
1543542192: No will message specified.
1543542192: Sending CONNACK to mosqsub|73254-MacBook-A (0, 0)
1543542192: Received SUBSCRIBE from mosqsub|73254-MacBook-A
1543542192:     animal (QoS 0)
1543542192: mosqsub|73254-MacBook-A 0 animal
1543542192: Sending SUBACK to mosqsub|73254-MacBook-A


1543542215: New connection from ::1 on port 1883.
1543542215: New client connected from ::1 as mosqpub|73257-MacBook-A (c1, k60).
1543542215: No will message specified.
1543542215: Sending CONNACK to mosqpub|73257-MacBook-A (0, 0)
1543542215: Received PUBLISH from mosqpub|73257-MacBook-A (d0, q0, r0, m0, 'animal', ... (3 bytes))
1543542215: Sending PUBLISH to mosqsub|73254-MacBook-A (d0, q0, r0, m0, 'animal', ... (3 bytes))
1543542215: Received DISCONNECT from mosqpub|73257-MacBook-A
1543542215: Client mosqpub|73257-MacBook-A disconnected.


1543542233: New connection from ::1 on port 1883.
1543542233: New client connected from ::1 as mosqpub|73267-MacBook-A (c1, k60).
1543542233: No will message specified.
1543542233: Sending CONNACK to mosqpub|73267-MacBook-A (0, 0)
1543542233: Received PUBLISH from mosqpub|73267-MacBook-A (d0, q0, r0, m0, 'animal', ... (3 bytes))
1543542233: Sending PUBLISH to mosqsub|73254-MacBook-A (d0, q0, r0, m0, 'animal', ... (3 bytes))
1543542233: Received DISCONNECT from mosqpub|73267-MacBook-A
1543542233: Client mosqpub|73267-MacBook-A disconnected.

文章首发: https://baijifeilong.github.io


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The Information

The Information

James Gleick / Vintage / 2012-3-6 / USD 16.95

James Gleick, the author of the best sellers Chaos and Genius, now brings us a work just as astonishing and masterly: a revelatory chronicle and meditation that shows how information has become th......一起来看看 《The Information》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具