| | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | |
| | | @Slf4j |
| | | @Slf4j(topic = "mqttCar") |
| | | public class MessageCallback implements MqttCallback { |
| | | |
| | | private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | |
| | | |
| | | @Override //消息发布者消息发布完成产生的回调 |
| | | public void deliveryComplete(IMqttDeliveryToken token) { |
| | | System.out.println("deliveryComplete---------" + token.isComplete()); |
| | | log.debug("deliveryComplete---------" + token.isComplete()); |
| | | int messageId = token.getMessageId(); |
| | | String[] topics = token.getTopics(); |
| | | String clientId = token.getClient().getClientId(); |
| | |
| | | topicStr = topicStr + topic + ","; |
| | | } |
| | | topicStr = topicStr.substring(0, topicStr.length() - 1); |
| | | System.out.println("消息发布完成,messageId="+messageId+",topics="+topicStr+",clientId="+clientId); |
| | | log.debug("消息发布完成,messageId="+messageId+",topics="+topicStr+",clientId="+clientId); |
| | | } |
| | | |
| | | @Override//消息订阅者收到消息后触发的回调 |
| | | public void messageArrived(String topic, MqttMessage message) throws Exception { |
| | | try { |
| | | System.out.println("【车辆锁主题】:"+topic+"【车辆锁信息】:"+new String(message.getPayload(), StandardCharsets.UTF_8)); |
| | | log.debug("【车辆锁主题】:"+topic+"【车辆锁信息】:"+new String(message.getPayload(), StandardCharsets.UTF_8)); |
| | | //出来回调数据 |
| | | List<ArdSyCarLock> ardSyCarLocks = carLockService.data(new String(message.getPayload(), StandardCharsets.UTF_8)); |
| | | //根据topic查询RTUID |