MqttConsumerCallBack.java 1.5 KB
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) {

    }

}