| | |
| | | package org.springblade.modules.rabbitmq.config; |
| | | |
| | | import org.springframework.amqp.core.*; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | |
| | | /** |
| | | * rabbitmq 配置文件 |
| | | * @author zhongrj |
| | | * @since 2022-04-08 |
| | | */ |
| | | @Configuration |
| | | public class MQConfig { |
| | | public static final String QUEUE = "queue"; |
| | | public static final String TOPIC_QUEUE1= "topic.queue1"; |
| | | public static final String TOPIC_QUEUE2 = "topic.queue2"; |
| | | public static final String TOPIC_EXCHANGE = "topicExchange"; |
| | | public static final String FANOUT_EXCHANGE = "fanoutxchage"; |
| | | public static final String TASK_QUEUE = "task_queue"; |
| | | |
| | | @Bean |
| | | public Queue taskQueue(){ |
| | | return new Queue(TASK_QUEUE,true); |
| | | } |
| | | |
| | | //Direct模式 |
| | | @Bean |
| | | public Queue queue(){ |
| | | return new Queue(QUEUE,true); |
| | | } |
| | | |
| | | //topic交换机模式 |
| | | @Bean |
| | | public Queue topicQueue1(){ |
| | | return new Queue(TOPIC_QUEUE1,true); |
| | | } |
| | | |
| | | @Bean |
| | | public Queue topicQueue2(){ |
| | | return new Queue(TOPIC_QUEUE2,true); |
| | | } |
| | | |
| | | @Bean |
| | | public TopicExchange topicExchange(){ |
| | | return new TopicExchange(TOPIC_EXCHANGE); |
| | | } |
| | | |
| | | @Bean |
| | | public Binding topicBinding1(){ |
| | | return BindingBuilder.bind(topicQueue1()).to(topicExchange()).with("topic.key1"); |
| | | } |
| | | |
| | | @Bean |
| | | public Binding topicBinding2(){ |
| | | return BindingBuilder.bind(topicQueue2()).to(topicExchange()).with("topic.#"); |
| | | } |
| | | |
| | | //Fanout模式,广播模式 |
| | | |
| | | @Bean |
| | | public FanoutExchange fanoutExchange(){ |
| | | return new FanoutExchange(FANOUT_EXCHANGE); |
| | | } |
| | | } |
| | | //package org.springblade.modules.rabbitmq.config; |
| | | // |
| | | //import org.springframework.amqp.core.*; |
| | | //import org.springframework.context.annotation.Bean; |
| | | //import org.springframework.context.annotation.Configuration; |
| | | // |
| | | ///** |
| | | // * rabbitmq 配置文件 |
| | | // * @author zhongrj |
| | | // * @since 2022-04-08 |
| | | // */ |
| | | //@Configuration |
| | | //public class MQConfig { |
| | | // public static final String QUEUE = "queue"; |
| | | // public static final String TOPIC_QUEUE1= "topic.queue1"; |
| | | // public static final String TOPIC_QUEUE2 = "topic.queue2"; |
| | | // public static final String TOPIC_EXCHANGE = "topicExchange"; |
| | | // public static final String FANOUT_EXCHANGE = "fanoutxchage"; |
| | | // public static final String TASK_QUEUE = "task_queue"; |
| | | // |
| | | // @Bean |
| | | // public Queue taskQueue(){ |
| | | // return new Queue(TASK_QUEUE,true); |
| | | // } |
| | | // |
| | | // //Direct模式 |
| | | // @Bean |
| | | // public Queue queue(){ |
| | | // return new Queue(QUEUE,true); |
| | | // } |
| | | // |
| | | // //topic交换机模式 |
| | | // @Bean |
| | | // public Queue topicQueue1(){ |
| | | // return new Queue(TOPIC_QUEUE1,true); |
| | | // } |
| | | // |
| | | // @Bean |
| | | // public Queue topicQueue2(){ |
| | | // return new Queue(TOPIC_QUEUE2,true); |
| | | // } |
| | | // |
| | | // @Bean |
| | | // public TopicExchange topicExchange(){ |
| | | // return new TopicExchange(TOPIC_EXCHANGE); |
| | | // } |
| | | // |
| | | // @Bean |
| | | // public Binding topicBinding1(){ |
| | | // return BindingBuilder.bind(topicQueue1()).to(topicExchange()).with("topic.key1"); |
| | | // } |
| | | // |
| | | // @Bean |
| | | // public Binding topicBinding2(){ |
| | | // return BindingBuilder.bind(topicQueue2()).to(topicExchange()).with("topic.#"); |
| | | // } |
| | | // |
| | | // //Fanout模式,广播模式 |
| | | // |
| | | // @Bean |
| | | // public FanoutExchange fanoutExchange(){ |
| | | // return new FanoutExchange(FANOUT_EXCHANGE); |
| | | // } |
| | | //} |