MQTT(这里采用的V2版本)发布消息的常见方法:

1、通过MQTT客户端连接MQTT服务器,建立长连接,通过接口发布消息

最常见的客户端:

  1. <dependency>
  2. <groupId>org.eclipse.paho</groupId>
  3. <artifactId>org.eclipse.paho.client.mqttv3</artifactId>
  4. <version>1.1.0</version>
  5. </dependency>

发布接口示例(连接过程省略...)

  1. //发布消息
  2. try {
  3. MqttMessage message = new MqttMessage();
  4. message.setQos(1); //保证消息能到达一次
  5. message.setRetained(true);
  6. message.setPayload("我喜欢做测试,咋地了捏".getBytes());
  7. client.publish(publishTopic,message);
  8. } catch (MqttException e) {
  9. System.out.println("publish fail");
  10. e.printStackTrace();
  11. }

2、通过MQTT提供的Rest接口发布消息

MQTT官网介绍:https://docs.emqx.io/broker/v2/cn/rest.html?highlight=post

postMan模拟

basic auth鉴权

发布的body

MQTT的Res接口发布消息的更多相关文章

  1. http接口封装mqtt协议

    前言 .Net Core 3.1 WebApi 列出了mqtt客户端的封装目的是为了了解运作机制 1.封装mqtt客户端 mqtt底层协议基于MQTTnet 版本2.8.5 github地址 实例化[ ...

  2. EMQ (Erlang/Enterprise/Elastic MQTT Broker)

    EMQ (Erlang/Enterprise/Elastic MQTT Broker) https://www.cnblogs.com/SteveLee/p/9843215.html MQ介绍 EMQ ...

  3. Spring Boot 集成 MQTT

    本文代码有些许问题,处理方案见:解决 spring-integration-mqtt 频繁报 Lost connection 错误 一.添加配置 spring: mqtt: client: usern ...

  4. MQTT 消息 发布 订阅

    当连接向一个mqtt服务器时,clientId必须是唯一的.设置一样,导致client.setCallback总是走到 connectionLost回调.报connection reset.调查一天才 ...

  5. emqtt 试用(三)mqtt 知识

    一.概念 MQTT 协议客户端库: https://github.com/mqtt/mqtt.github.io/wiki/libraries 例如,mosquitto_sub/pub 命令行发布订阅 ...

  6. 【Qt官方MQTT库的使用,附一个MqttClient例子】

    Qt官方MQTT库的使用,附一个MqttClient例子 开发环境:win7 64 + Qt5.9 记录时间:2018年3月11日 00:48:42 联系邮箱: yexiaopeng1992@126. ...

  7. python语言(六)mock接口开发、发邮件、写日志、新Excel操作

    一.urllib模块 urllib模块是一个标准模块,直接import urllib即可,在python3里面只有urllib模块,在python2里面有urllib模块和urllib2模块. url ...

  8. MQTT 协议学习:008-在STM32上移植MQTT

    前言 通过前面了解MQTT有关概念.分析了有关的报文,我们对于这个协议也有了更深的认识.但纸上谈来终觉浅,绝知此事要躬行. 本文参考:<STM32+W5500+MQTT+Android实现远程数 ...

  9. windows 下搭建 MQTT 服务

    1.首先搭建起MQTT服务 1.1安装mosquitto,mosquitto是开源的MQTT代理服务器,它的Windows安装包地址:https://mosquitto.org/download/ 1 ...

随机推荐

  1. python--基于socket网络编程

    Python 提供了两个基本的 socket 模块. 第一个是 Socket,它提供了标准的 BSD Sockets API. 第二个是 SocketServer, 它提供了服务器中心类,可以简化网络 ...

  2. vim文本编辑器——文件导入、命令查找、导入命令执行结果、自定义快捷键、ab命令、快捷键的保存

    1.文件的导入(r): 导入前: 导入后: 在光标处,将tmp目录下的zhbb文件的内容导入到了当前文件. 2.命令的查找: 3.导入命令的执行结果: 光标所在行为导入的位置. 4.自定义快捷键: ( ...

  3. PHP Record the number of login users

    Function to record how many times the user logs in Connect to the database first: you can create a n ...

  4. vue-axios interceptors

    import axios from 'axios' import cookie from 'js-cookie' const options = { baseURL: window.location. ...

  5. Cookie 的 SameSite 属性

    转自http://www.ruanyifeng.com/blog/2019/09/cookie-samesite.html Chrome 51 开始,浏览器的 Cookie 新增加了一个SameSit ...

  6. python: str()

    tx1 = '中国' tx2 = u'中国' print tx1 print tx2 print type(tx1) print type(tx2) #<type 'str'> str() ...

  7. Xshell远程登录

    1.xshell由一台服务器a登录另一台服务器b sftp -oPort = root@ip 2.下载git /上传pull git b服务器想下载的目标文件目录 a服务器上的文件下载目录

  8. Note for Reidentification by Relative Distance Comparison

    link Reidentification by Relative Distance Comparison Challenge: large visual appearance changes cau ...

  9. IntelliJ IDEA 运行你的第一个Java应用程序 idea运行main方法

    IntelliJ IDEA 运行你的第一个Java应用程序创建项目让我们创建一个简单的Java Hello World项目. 单击创建新的项目. 打开新建项目向导.你应该注意的主要是项目的SDK.SD ...

  10. linux安装chrome及chromedriver(转)

    1.chrome: curl https://intoli.com/install-google-chrome.sh | bash 1.1.centos安装chrome: 從 Google 下載最新版 ...