|
|
@@ -1,33 +1,58 @@
|
|
|
package com.kym.service.queue.config;
|
|
|
|
|
|
+import com.kym.entity.common.Exchanges;
|
|
|
+import com.kym.entity.common.Queues;
|
|
|
+import com.kym.entity.common.RoutingKeys;
|
|
|
import org.springframework.amqp.core.Binding;
|
|
|
import org.springframework.amqp.core.BindingBuilder;
|
|
|
-import org.springframework.amqp.core.FanoutExchange;
|
|
|
+import org.springframework.amqp.core.CustomExchange;
|
|
|
import org.springframework.amqp.core.Queue;
|
|
|
-import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
|
|
|
@Configuration
|
|
|
public class QueueConfig {
|
|
|
|
|
|
- @Bean(name = "confirmTestQueue")
|
|
|
- public Queue confirmTestQueue() {
|
|
|
- return new Queue("confirm_test_queue", true, false, false);
|
|
|
+ /**
|
|
|
+ * 延迟交换机的类型
|
|
|
+ */
|
|
|
+ public static final String DELAY_EXCHANGE_TYPE = "x-delayed-message";
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 延迟队列
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Bean(name = "delayQueue")
|
|
|
+ public Queue delayQueue() {
|
|
|
+ return new Queue(Queues.DELAY_QUEUE, true, false, false);
|
|
|
}
|
|
|
|
|
|
- @Bean(name = "confirmTestExchange")
|
|
|
- public FanoutExchange confirmTestExchange() {
|
|
|
- return new FanoutExchange("confirmTestExchange");
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建延迟交换机,必须先创建才能监听
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Bean
|
|
|
+ public CustomExchange delayExchange() {
|
|
|
+ Map<String, Object> args = new HashMap<>();
|
|
|
+ args.put("x-delayed-type", "direct");
|
|
|
+ //属性参数 交换机名称 交换机类型 是否持久化 是否自动删除 配置参数
|
|
|
+ return new CustomExchange(Exchanges.DELAY_EXCHANGE_NAME, DELAY_EXCHANGE_TYPE, true, false, args);
|
|
|
}
|
|
|
|
|
|
@Bean
|
|
|
- public Binding confirmTestFanoutExchangeAndQueue(
|
|
|
- @Qualifier("confirmTestExchange") FanoutExchange confirmTestExchange,
|
|
|
- @Qualifier("confirmTestQueue") Queue confirmTestQueue) {
|
|
|
- return BindingBuilder.bind(confirmTestQueue).to(confirmTestExchange);
|
|
|
+ public Binding binding() {
|
|
|
+ return BindingBuilder.bind(delayQueue()).to(delayExchange()).with(RoutingKeys.DELAY_ROUTING_KEY).noargs();
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|