| | |
| | | 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.beans.factory.annotation.Value; |
| | | import org.springframework.integration.annotation.Router; |
| | | import org.springframework.integration.mqtt.support.MqttHeaders; |
| | | import org.springframework.integration.router.AbstractMessageRouter; |
| | |
| | | @Component |
| | | @Slf4j |
| | | public class InboundMessageRouter extends AbstractMessageRouter { |
| | | @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. |
| | |
| | | |
| | | DeviceTopicEnum topicEnum = DeviceTopicEnum.find(topic); |
| | | MessageChannel bean = (MessageChannel) SpringBeanUtils.getBean(topicEnum.getBeanName()); |
| | | |
| | | String msg = new String(payload); |
| | | try { |
| | | if (isOpen){ |
| | | mqttMsgProxyProducer.publish(topic.replace("/","."), msg); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("消息发送失败:", e); |
| | | } |
| | | return Collections.singleton(bean); |
| | | } |
| | | } |