MqttConsumerCallBack.java
1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.skua.modules.remotemeeting.mqtt;
import com.skua.modules.remotemeeting.service.IRemoteMeetingService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttMessage;
@AllArgsConstructor
@Slf4j
public class MqttConsumerCallBack implements MqttCallback{
IRemoteMeetingService remoteMeetingService;
MqttClient client;
/**
* 客户端断开连接的回调
*/
@Override
public void connectionLost(Throwable throwable) {
log.error("第三方远程AR会议-mqtt与服务器断开连接", throwable);
//设置了自动重连
}
/**
* 消息到达的回调
*/
@Override
public void messageArrived(String topic, MqttMessage message) throws Exception {
log.info(String.format("第三方远程AR会议-收到mqtt消息:消息主题 = %s 消息Qos :=%d 消息内容 = %s",topic,message.getQos(),new String(message.getPayload())));
try{
remoteMeetingService.processMqttMsg(topic, new String(message.getPayload()));
}catch (Exception e){
log.error("第三方远程AR会议-mqtt消息处理失败", e);
}
}
/**
* 消息发布成功的回调
*/
@Override
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
}
}