|
|
@@ -2,8 +2,8 @@ package com.yunfeiyun.agmp.iots.mq.bussiness;
|
|
|
|
|
|
import com.yunfeiyun.agmp.iot.common.constant.mq.IotMqExchange;
|
|
|
import com.yunfeiyun.agmp.iot.common.constant.mq.IotMqQueue;
|
|
|
-
|
|
|
-import com.yunfeiyun.agmp.iots.mq.listener.IotmChannelAwareMessageListener;
|
|
|
+import com.yunfeiyun.agmp.iots.mq.listener.IotmBaseDataChannelAwareMessageListener;
|
|
|
+import com.yunfeiyun.agmp.iots.mq.listener.IotmCmdChannelAwareMessageListener;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.amqp.core.*;
|
|
|
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
|
|
@@ -36,10 +36,15 @@ public class AgmpMqBusConfig {
|
|
|
*/
|
|
|
@PostConstruct
|
|
|
public void init() {
|
|
|
- log.info("加载Agmp Mq");
|
|
|
- agmpAmqpAdmin.declareQueue(agmpQueue());
|
|
|
- agmpAmqpAdmin.declareExchange(agmpExchange());
|
|
|
- agmpAmqpAdmin.declareBinding(agmpBinding());
|
|
|
+ log.info("加载Cmd Mq");
|
|
|
+ agmpAmqpAdmin.declareQueue(iotmToIotsCmdQueue());
|
|
|
+ agmpAmqpAdmin.declareExchange(iotmToIotsCmdExchange());
|
|
|
+ agmpAmqpAdmin.declareBinding(iotmToIotsCmdBinding());
|
|
|
+ log.info("加载Base Data Mq");
|
|
|
+ agmpAmqpAdmin.declareQueue(iotmToIotsCmdQueue());
|
|
|
+ agmpAmqpAdmin.declareExchange(iotmToIotsCmdExchange());
|
|
|
+ agmpAmqpAdmin.declareBinding(iotmToIotsCmdBinding());
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -47,8 +52,8 @@ public class AgmpMqBusConfig {
|
|
|
*
|
|
|
* @return 队列对象
|
|
|
*/
|
|
|
- @Bean("agmpQueue")
|
|
|
- public Queue agmpQueue() {
|
|
|
+ @Bean("iotmToIotsCmdQueue")
|
|
|
+ public Queue iotmToIotsCmdQueue() {
|
|
|
return QueueBuilder.durable(IotMqQueue.IOTM_TO_IOTS_CMD_QUEUE).build();
|
|
|
}
|
|
|
|
|
|
@@ -57,8 +62,8 @@ public class AgmpMqBusConfig {
|
|
|
*
|
|
|
* @return 交换机对象
|
|
|
*/
|
|
|
- @Bean("agmpExchange")
|
|
|
- public FanoutExchange agmpExchange() {
|
|
|
+ @Bean("iotmToIotsCmdExchange")
|
|
|
+ public FanoutExchange iotmToIotsCmdExchange() {
|
|
|
return new FanoutExchange(IotMqExchange.IOTM_TO_IOTS_EXCHANGE);
|
|
|
}
|
|
|
|
|
|
@@ -67,9 +72,39 @@ public class AgmpMqBusConfig {
|
|
|
*
|
|
|
* @return 绑定对象
|
|
|
*/
|
|
|
- @Bean("agmpBinding")
|
|
|
- public Binding agmpBinding() {
|
|
|
- return BindingBuilder.bind(agmpQueue()).to(agmpExchange());
|
|
|
+ @Bean("iotmToIotsCmdBinding")
|
|
|
+ public Binding iotmToIotsCmdBinding() {
|
|
|
+ return BindingBuilder.bind(iotmToIotsCmdQueue()).to(iotmToIotsCmdExchange());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 定义一个持久化的队列
|
|
|
+ *
|
|
|
+ * @return 队列对象
|
|
|
+ */
|
|
|
+ @Bean("iotmToIotsBaseDataQueue")
|
|
|
+ public Queue iotmToIotsBaseDataQueue() {
|
|
|
+ return QueueBuilder.durable(IotMqQueue.IOTM_TO_IOTS_CMD_QUEUE).build();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 定义一个主题交换机
|
|
|
+ *
|
|
|
+ * @return 交换机对象
|
|
|
+ */
|
|
|
+ @Bean("iotmToIotsBaseDataExchange")
|
|
|
+ public FanoutExchange iotmToIotsBaseDataExchange() {
|
|
|
+ return new FanoutExchange(IotMqExchange.IOTM_TO_IOTS_EXCHANGE);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 定义队列与交换机的绑定关系
|
|
|
+ *
|
|
|
+ * @return 绑定对象
|
|
|
+ */
|
|
|
+ @Bean("iotmToIotsBaseDataBinding")
|
|
|
+ public Binding iotmToIotsBaseDataBinding() {
|
|
|
+ return BindingBuilder.bind(iotmToIotsBaseDataQueue()).to(iotmToIotsBaseDataExchange());
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -80,17 +115,35 @@ public class AgmpMqBusConfig {
|
|
|
* @param listener 消息监听器
|
|
|
* @return 消息监听器容器
|
|
|
*/
|
|
|
- @Bean("agmpSimpleMessageListenerContainer")
|
|
|
- public SimpleMessageListenerContainer agmpSimpleMessageListenerContainer(
|
|
|
+ @Bean("iotmBaseDataMessageListenerContainer")
|
|
|
+ public SimpleMessageListenerContainer iotmBaseDataMessageListenerContainer(
|
|
|
@Qualifier("agmpConnectionFactory") CachingConnectionFactory connectionFactory,
|
|
|
- IotmChannelAwareMessageListener listener) {
|
|
|
+ IotmBaseDataChannelAwareMessageListener listener) {
|
|
|
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory);
|
|
|
- container.setQueues(agmpQueue());
|
|
|
+ container.setQueues(iotmToIotsBaseDataQueue());
|
|
|
+ container.setMessageListener(listener);
|
|
|
+ // 设置确认模式为自动确认
|
|
|
+ container.setAcknowledgeMode(AcknowledgeMode.MANUAL);
|
|
|
+ container.setAmqpAdmin(agmpAmqpAdmin);
|
|
|
+ return container;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 配置一个具体的消息监听器容器,用于监听特定的队列并处理消息
|
|
|
+ *
|
|
|
+ * @param connectionFactory 连接工厂
|
|
|
+ * @param listener 消息监听器
|
|
|
+ * @return 消息监听器容器
|
|
|
+ */
|
|
|
+ @Bean("iotmCmdMessageListenerContainer")
|
|
|
+ public SimpleMessageListenerContainer iotmCmdMessageListenerContainer(
|
|
|
+ @Qualifier("agmpConnectionFactory") CachingConnectionFactory connectionFactory,
|
|
|
+ IotmCmdChannelAwareMessageListener listener) {
|
|
|
+ SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory);
|
|
|
+ container.setQueues(iotmToIotsCmdQueue());
|
|
|
container.setMessageListener(listener);
|
|
|
// 设置确认模式为自动确认
|
|
|
container.setAcknowledgeMode(AcknowledgeMode.MANUAL);
|
|
|
container.setAmqpAdmin(agmpAmqpAdmin);
|
|
|
-
|
|
|
return container;
|
|
|
}
|
|
|
|