| | |
| | | |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | | import com.ruoyi.sy.service.ArdSyCarRtuService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.eclipse.paho.client.mqttv3.IMqttClient; |
| | | import org.eclipse.paho.client.mqttv3.MqttClient; |
| | | import org.eclipse.paho.client.mqttv3.MqttClientPersistence; |
| | |
| | | import org.eclipse.paho.client.mqttv3.MqttMessage; |
| | | import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; |
| | | |
| | | @Slf4j(topic = "mqttCar") |
| | | public class EmqClient { |
| | | |
| | | private IMqttClient mqttClient; |
| | |
| | | this.mqttClient = new MqttClient(mqttUrl,clientId,mempersitence);//设置连接broker的host及clientId |
| | | this.messageCallback = new MessageCallback(); |
| | | } catch (MqttException e) { |
| | | System.out.println("初始化客户端mqttClient对象失败"); |
| | | System.out.println("brokerUrl:"+mqttUrl); |
| | | System.out.println("clientId:"+clientId); |
| | | e.getMessage(); |
| | | } |
| | | } |
| | |
| | | options.setUserName("admin"); |
| | | options.setPassword("xzx12345".toCharArray()); |
| | | options.setCleanSession(true);//设置为临时会话 |
| | | |
| | | mqttClient.setCallback(messageCallback);//设置回调 |
| | | |
| | | try { |