aix
2024-07-09 2aaaaf4598b869085ae35871de018cd35847c232
src/main/java/com/dji/sample/component/mqtt/handler/InboundMessageRouter.java
@@ -3,9 +3,10 @@
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 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;
@@ -26,8 +27,11 @@
@Component
@Slf4j
public class InboundMessageRouter extends AbstractMessageRouter {
    /*@Autowired
    private MqttMsgProxyProducer mqttMsgProxyProducer;*/
    @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.
@@ -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);
        }