|
| 1 | +package com.baeldung.springamqpsimple.broadcast; |
| 2 | + |
| 3 | +import org.springframework.amqp.core.BindingBuilder; |
| 4 | +import org.springframework.amqp.core.Declarable; |
| 5 | +import org.springframework.amqp.core.DirectExchange; |
| 6 | +import org.springframework.amqp.core.FanoutExchange; |
| 7 | +import org.springframework.amqp.core.Queue; |
| 8 | +import org.springframework.amqp.core.TopicExchange; |
| 9 | +import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory; |
| 10 | +import org.springframework.amqp.rabbit.connection.ConnectionFactory; |
| 11 | +import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer; |
| 12 | +import org.springframework.context.annotation.Bean; |
| 13 | +import org.springframework.context.annotation.Configuration; |
| 14 | +import org.springframework.context.annotation.Profile; |
| 15 | + |
| 16 | +import java.util.Arrays; |
| 17 | +import java.util.List; |
| 18 | + |
| 19 | +@Configuration |
| 20 | +@Profile("!test") |
| 21 | +public class BroadcastConfig { |
| 22 | + |
| 23 | + public final static String fanoutQueue1Name = "com.baeldung.spring-amqp-simple.fanout.queue1"; |
| 24 | + public final static String fanoutQueue2Name = "com.baeldung.spring-amqp-simple.fanout.queue2"; |
| 25 | + public final static String fanoutExchangeName = "com.baeldung.spring-amqp-simple.fanout.exchange"; |
| 26 | + |
| 27 | + public final static String topicQueue1Name = "com.baeldung.spring-amqp-simple.topic.queue1"; |
| 28 | + public final static String topicQueue2Name = "com.baeldung.spring-amqp-simple.topic.queue2"; |
| 29 | + public final static String topicExchangeName = "com.baeldung.spring-amql-simple.topic.exchange"; |
| 30 | + |
| 31 | + @Bean |
| 32 | + public List<Declarable> topicBindings() { |
| 33 | + Queue topicQueue1 = new Queue(topicQueue1Name, false); |
| 34 | + Queue topicQueue2 = new Queue(topicQueue2Name, false); |
| 35 | + |
| 36 | + TopicExchange topicExchange = new TopicExchange(topicExchangeName); |
| 37 | + |
| 38 | + return Arrays.asList( |
| 39 | + topicQueue1, |
| 40 | + topicQueue2, |
| 41 | + topicExchange, |
| 42 | + BindingBuilder.bind(topicQueue1).to(topicExchange).with("*.important.*"), |
| 43 | + BindingBuilder.bind(topicQueue2).to(topicExchange).with("user.#") |
| 44 | + ); |
| 45 | + } |
| 46 | + |
| 47 | + @Bean |
| 48 | + public List<Declarable> fanoutBindings() { |
| 49 | + Queue fanoutQueue1 = new Queue(fanoutQueue1Name, false); |
| 50 | + Queue fanoutQueue2 = new Queue(fanoutQueue2Name, false); |
| 51 | + |
| 52 | + FanoutExchange fanoutExchange = new FanoutExchange(fanoutExchangeName); |
| 53 | + |
| 54 | + return Arrays.asList( |
| 55 | + fanoutQueue1, |
| 56 | + fanoutQueue2, |
| 57 | + fanoutExchange, |
| 58 | + BindingBuilder.bind(fanoutQueue1).to(fanoutExchange), |
| 59 | + BindingBuilder.bind(fanoutQueue2).to(fanoutExchange) |
| 60 | + ); |
| 61 | + } |
| 62 | + |
| 63 | + @Bean |
| 64 | + public SimpleRabbitListenerContainerFactory container(ConnectionFactory connectionFactory, SimpleRabbitListenerContainerFactoryConfigurer configurer) { |
| 65 | + SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory(); |
| 66 | + configurer.configure(factory, connectionFactory); |
| 67 | + return factory; |
| 68 | + } |
| 69 | + |
| 70 | +} |
0 commit comments