文章目录
概要
两个springboot项目,一个作为发布方,一个作为订阅方,模拟设备向服务器发送mqtt请求上报消息,示例使用的是emqx官网的免费mqtt服务器,实际开发中可以使用搭建的mqtt服务器
发布方(模拟设备)
引入pom
<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>1.2.5</version>
</dependency>
回调MqttCallback
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttMessage;
public class OnMessageCallback implements MqttCallback {
@Override
public void connectionLost(Throwable cause) {
}
@Override
public void messageArrived(String topic, MqttMessage message) throws Exception {
}
@Override
public void deliveryComplete(IMqttDeliveryToken token) {
}
}
发布的方法
import com.sci.web.system.controller.dev.OnMessageCallback;
import io.swagger.annotations.*;
import org.eclipse.paho.client.mqttv3.*;
import
标签:mqttv3,eclipse,单向,第七篇,mqtt,import,org,paho,MqttCallback
From: https://blog.csdn.net/uutale/article/details/140149384