| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.eclipse.paho.client.mqttv3.*; |
| | | import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | |
| | | /** |
| | | * @author ZhuBaoMin |
| | |
| | | @Slf4j |
| | | public class MqttMsgSubscriber { |
| | | |
| | | @Value("${spring.mqtt.broker}") |
| | | private String broker; |
| | | |
| | | @Value("${spring.mqtt.username}") |
| | | private String username; |
| | | |
| | | @Value("${spring.mqtt.password}") |
| | | private String password; |
| | | |
| | | @Value("${spring.mqtt.topic}") |
| | | private String topic; |
| | | |
| | | @Value("${spring.mqtt.qos}") |
| | | private Integer qos; |
| | | |
| | | private String clientId = System.currentTimeMillis() + ""; |
| | | |
| | | public void readSubscribeTopicMessage(){ |
| | | try { |
| | | String broker = "tcp://127.0.0.1:1883"; |
| | | String username = "mqtt_u"; |
| | | String password = "yjy"; |
| | | String topic = "workOrder"; |
| | | Integer qos = 2; |
| | | String clientId = System.currentTimeMillis() + ""; |
| | | |
| | | MqttClient client = new MqttClient(broker, clientId, new MemoryPersistence()); |
| | | |
| | | // 连接参数 |