aix
2024-08-08 39ffdf5754b4ebca682bd3c925f7a500e8a1bbda
src/main/java/com/dji/sample/component/mqtt/handler/InboundMessageRouter.java
@@ -6,6 +6,7 @@
import com.dji.sample.component.rabbitmq.config.MqttMsgProxyProducer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.integration.annotation.Router;
import org.springframework.integration.mqtt.support.MqttHeaders;
import org.springframework.integration.router.AbstractMessageRouter;
@@ -29,6 +30,9 @@
    @Autowired
    private MqttMsgProxyProducer mqttMsgProxyProducer;
    @Value("${spring.rabbitmq.is-open}")
    private Boolean isOpen;
    /**
     * All mqtt broker messages will arrive here before distributing them to different channels.
     * @param message message from mqtt broker
@@ -47,7 +51,9 @@
        MessageChannel bean = (MessageChannel) SpringBeanUtils.getBean(topicEnum.getBeanName());
        String msg = new String(payload);
        try {
            mqttMsgProxyProducer.publish(topic.replace("/","."), msg);
            if (isOpen){
                mqttMsgProxyProducer.publish(topic.replace("/","."), msg);
            }
        } catch (Exception e) {
            log.error("消息发送失败:", e);
        }