From 4f948b26f8b6367f133c183838b6253ea755c3e7 Mon Sep 17 00:00:00 2001 From: pcoates Date: Fri, 2 Aug 2019 16:43:35 +0100 Subject: [PATCH] BAEL-2688 Moved example code from spring-amqp-simple to spring-amqp project. Also updated for Spring Boot. --- parent-boot-2/pom.xml | 12 ------- .../springamqpsimple/SpringAmqpConfig.java | 1 - .../broadcast/BroadcastConfig.java | 19 ++++------ .../org/baeldung/SpringContextManualTest.java | 3 +- spring-amqp/README.md | 3 +- spring-amqp/pom.xml | 23 +++--------- .../springamqp/consumer/Consumer.java | 7 ---- .../springamqp/producer/Producer.java | 17 --------- spring-amqp/src/main/resources/beans.xml | 35 ------------------- spring-amqp/src/main/resources/logback.xml | 13 ------- 10 files changed, 13 insertions(+), 120 deletions(-) delete mode 100644 spring-amqp/src/main/java/com/baeldung/springamqp/consumer/Consumer.java delete mode 100644 spring-amqp/src/main/java/com/baeldung/springamqp/producer/Producer.java delete mode 100644 spring-amqp/src/main/resources/beans.xml delete mode 100644 spring-amqp/src/main/resources/logback.xml diff --git a/parent-boot-2/pom.xml b/parent-boot-2/pom.xml index f0e921bf37..a91766f772 100644 --- a/parent-boot-2/pom.xml +++ b/parent-boot-2/pom.xml @@ -43,10 +43,6 @@ org.springframework.boot spring-boot-maven-plugin ${spring-boot.version} - - ${start-class} - - @@ -60,14 +56,6 @@ org.springframework.boot spring-boot-maven-plugin - - - - org.springframework.boot.experimental - spring-boot-thin-layout - ${thin.version} - - diff --git a/spring-amqp-simple/src/main/java/com/baeldung/springamqpsimple/SpringAmqpConfig.java b/spring-amqp-simple/src/main/java/com/baeldung/springamqpsimple/SpringAmqpConfig.java index 92fa28ed6f..5a2f6e4c96 100644 --- a/spring-amqp-simple/src/main/java/com/baeldung/springamqpsimple/SpringAmqpConfig.java +++ b/spring-amqp-simple/src/main/java/com/baeldung/springamqpsimple/SpringAmqpConfig.java @@ -13,7 +13,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; @Configuration -@Profile("!test") public class SpringAmqpConfig { public final static String queueName = "com.baeldung.spring-amqp-simple.queue"; diff --git a/spring-amqp-simple/src/main/java/com/baeldung/springamqpsimple/broadcast/BroadcastConfig.java b/spring-amqp-simple/src/main/java/com/baeldung/springamqpsimple/broadcast/BroadcastConfig.java index 868cfff0ac..35f906a7fc 100644 --- a/spring-amqp-simple/src/main/java/com/baeldung/springamqpsimple/broadcast/BroadcastConfig.java +++ b/spring-amqp-simple/src/main/java/com/baeldung/springamqpsimple/broadcast/BroadcastConfig.java @@ -1,11 +1,6 @@ package com.baeldung.springamqpsimple.broadcast; -import org.springframework.amqp.core.BindingBuilder; -import org.springframework.amqp.core.Declarable; -import org.springframework.amqp.core.DirectExchange; -import org.springframework.amqp.core.FanoutExchange; -import org.springframework.amqp.core.Queue; -import org.springframework.amqp.core.TopicExchange; +import org.springframework.amqp.core.*; import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory; import org.springframework.amqp.rabbit.connection.ConnectionFactory; import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer; @@ -17,7 +12,6 @@ import java.util.Arrays; import java.util.List; @Configuration -@Profile("!test") public class BroadcastConfig { public final static String fanoutQueue1Name = "com.baeldung.spring-amqp-simple.fanout.queue1"; @@ -29,29 +23,28 @@ public class BroadcastConfig { public final static String topicExchangeName = "com.baeldung.spring-amql-simple.topic.exchange"; @Bean - public List topicBindings() { + public Declarables topicBindings() { Queue topicQueue1 = new Queue(topicQueue1Name, false); Queue topicQueue2 = new Queue(topicQueue2Name, false); TopicExchange topicExchange = new TopicExchange(topicExchangeName); - return Arrays.asList( + return new Declarables( topicQueue1, topicQueue2, topicExchange, BindingBuilder.bind(topicQueue1).to(topicExchange).with("*.important.*"), - BindingBuilder.bind(topicQueue2).to(topicExchange).with("user.#") - ); + BindingBuilder.bind(topicQueue2).to(topicExchange).with("user.#")); } @Bean - public List fanoutBindings() { + public Declarables fanoutBindings() { Queue fanoutQueue1 = new Queue(fanoutQueue1Name, false); Queue fanoutQueue2 = new Queue(fanoutQueue2Name, false); FanoutExchange fanoutExchange = new FanoutExchange(fanoutExchangeName); - return Arrays.asList( + return new Declarables( fanoutQueue1, fanoutQueue2, fanoutExchange, diff --git a/spring-amqp-simple/src/test/java/org/baeldung/SpringContextManualTest.java b/spring-amqp-simple/src/test/java/org/baeldung/SpringContextManualTest.java index 03cb34eeb5..d51017d07a 100644 --- a/spring-amqp-simple/src/test/java/org/baeldung/SpringContextManualTest.java +++ b/spring-amqp-simple/src/test/java/org/baeldung/SpringContextManualTest.java @@ -1,12 +1,11 @@ package org.baeldung; +import com.baeldung.springamqpsimple.SpringAmqpApplication; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; -import com.baeldung.springamqpsimple.SpringAmqpApplication; - @RunWith(SpringRunner.class) @SpringBootTest(classes = SpringAmqpApplication.class) public class SpringContextManualTest { diff --git a/spring-amqp/README.md b/spring-amqp/README.md index b0d16c9305..5e29011995 100644 --- a/spring-amqp/README.md +++ b/spring-amqp/README.md @@ -1,3 +1,4 @@ ## Relevant articles: -- [Messaging With Spring AMQP](http://www.baeldung.com/spring-amqp) +- [Messaging With Spring AMQP](https://www.baeldung.com/spring-amqp) +- [RabbitMQ Message Dispatching with Spring AMQP](https://www.baeldung.com/rabbitmq-spring-amqp) \ No newline at end of file diff --git a/spring-amqp/pom.xml b/spring-amqp/pom.xml index c021bd49ff..642d35b44e 100755 --- a/spring-amqp/pom.xml +++ b/spring-amqp/pom.xml @@ -9,31 +9,16 @@ Introduction to Spring-AMQP + parent-boot-2 com.baeldung - parent-modules - 1.0.0-SNAPSHOT + 0.0.1-SNAPSHOT - org.springframework.amqp - spring-rabbit - ${spring-rabbit} - - - commons-logging - commons-logging - - + org.springframework.boot + spring-boot-starter-amqp - - spring-amqp - - - - 1.6.6.RELEASE - - diff --git a/spring-amqp/src/main/java/com/baeldung/springamqp/consumer/Consumer.java b/spring-amqp/src/main/java/com/baeldung/springamqp/consumer/Consumer.java deleted file mode 100644 index 42d7e88cbd..0000000000 --- a/spring-amqp/src/main/java/com/baeldung/springamqp/consumer/Consumer.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.baeldung.springamqp.consumer; - -public class Consumer { - public void listen(String foo) { - System.out.println(foo); - } -} \ No newline at end of file diff --git a/spring-amqp/src/main/java/com/baeldung/springamqp/producer/Producer.java b/spring-amqp/src/main/java/com/baeldung/springamqp/producer/Producer.java deleted file mode 100644 index b4067ed795..0000000000 --- a/spring-amqp/src/main/java/com/baeldung/springamqp/producer/Producer.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung.springamqp.producer; - -import org.springframework.amqp.core.AmqpTemplate; -import org.springframework.amqp.rabbit.core.RabbitTemplate; -import org.springframework.context.support.AbstractApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; - -public class Producer { - - public static void main(String[] args) throws InterruptedException { - AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml"); - AmqpTemplate template = ctx.getBean(RabbitTemplate.class); - template.convertAndSend("Hello, world!"); - Thread.sleep(1000); - ctx.destroy(); - } -} \ No newline at end of file diff --git a/spring-amqp/src/main/resources/beans.xml b/spring-amqp/src/main/resources/beans.xml deleted file mode 100644 index f6a966b0f6..0000000000 --- a/spring-amqp/src/main/resources/beans.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/spring-amqp/src/main/resources/logback.xml b/spring-amqp/src/main/resources/logback.xml deleted file mode 100644 index 7d900d8ea8..0000000000 --- a/spring-amqp/src/main/resources/logback.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - - \ No newline at end of file