New file |
| | |
| | | package com.dy.pipIrrApp.workOrder.mqtt; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.eclipse.paho.client.mqttv3.MqttClient; |
| | | import org.eclipse.paho.client.mqttv3.MqttException; |
| | | import org.eclipse.paho.client.mqttv3.MqttMessage; |
| | | |
| | | /** |
| | | * @author ZhuBaoMin |
| | | * @date 2024-11-16 11:28 |
| | | * @LastEditTime 2024-11-16 11:28 |
| | | * @Description 消息发送方法 |
| | | */ |
| | | |
| | | @Slf4j |
| | | public class MqttMsgSender { |
| | | public void sendMessage(MqttClient client, String topic, String content, int qos){ |
| | | MqttMessage message = new MqttMessage(content.getBytes()); |
| | | message.setQos(qos); |
| | | try{ |
| | | client.publish(topic,message); |
| | | } catch (MqttException e){ |
| | | log.error("MqttClient publish text info Error:{}!", e.getMessage()); |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |