shenyijian
2023-11-28 a0ad613e75498fb4331b7f3eb55b60cec7896d88
src/main/java/com/dji/sample/component/mqtt/handler/InboundMessageRouter.java
@@ -3,7 +3,9 @@
import com.dji.sample.common.util.SpringBeanUtils;
import com.dji.sample.component.mqtt.model.ChannelName;
import com.dji.sample.component.mqtt.model.DeviceTopicEnum;
//import com.dji.sample.component.rabbitmq.config.MqttMsgProxyProducer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.annotation.Router;
import org.springframework.integration.mqtt.support.MqttHeaders;
import org.springframework.integration.router.AbstractMessageRouter;
@@ -24,6 +26,8 @@
@Component
@Slf4j
public class InboundMessageRouter extends AbstractMessageRouter {
    /*@Autowired
    private MqttMsgProxyProducer mqttMsgProxyProducer;*/
    /**
     * All mqtt broker messages will arrive here before distributing them to different channels.
@@ -41,7 +45,12 @@
        DeviceTopicEnum topicEnum = DeviceTopicEnum.find(topic);
        MessageChannel bean = (MessageChannel) SpringBeanUtils.getBean(topicEnum.getBeanName());
        String msg = new String(payload);
        try {
//            mqttMsgProxyProducer.publish(topic.replace("/","."), msg);
        } catch (Exception e) {
            log.error("消息发送失败:", e);
        }
        return Collections.singleton(bean);
    }
}