|
@@ -0,0 +1,44 @@
|
|
|
+package com.sf.config;
|
|
|
+
|
|
|
+import org.springframework.amqp.core.Binding;
|
|
|
+import org.springframework.amqp.core.BindingBuilder;
|
|
|
+import org.springframework.amqp.core.FanoutExchange;
|
|
|
+import org.springframework.amqp.core.Queue;
|
|
|
+import org.springframework.context.annotation.Bean;
|
|
|
+import org.springframework.context.annotation.Configuration;
|
|
|
+
|
|
|
+@Configuration
|
|
|
+public class FanoutConfig {
|
|
|
+
|
|
|
+ // 这里也是创建一个持久化的交换机
|
|
|
+ // 要么是交换机已创建 并且是持久化的
|
|
|
+ // 要么是交换机未创建
|
|
|
+ // 对应解决方案是 要么删掉旧的 要么给一个新的
|
|
|
+ @Bean
|
|
|
+ public FanoutExchange fanoutExchange(){
|
|
|
+ return new FanoutExchange("fanoutExchange1");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Bean
|
|
|
+ public Queue fanoutQueue(){
|
|
|
+ return new Queue("fanoutQueue");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 此处方法的入参名要和前面声明的bean名称 保持一致
|
|
|
+ @Bean
|
|
|
+ public Binding fanoutBinding(Queue fanoutQueue, FanoutExchange fanoutExchange){
|
|
|
+ // 将队列绑定到交换机上
|
|
|
+ return BindingBuilder.bind(fanoutQueue).to(fanoutExchange);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Bean
|
|
|
+ public Queue fanoutQueue2(){
|
|
|
+ return new Queue("fanoutQueue2");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 绑定第二个队列
|
|
|
+ @Bean
|
|
|
+ public Binding fanoutBinding2(Queue fanoutQueue2, FanoutExchange fanoutExchange){
|
|
|
+ return BindingBuilder.bind(fanoutQueue2).to(fanoutExchange);
|
|
|
+ }
|
|
|
+}
|