Skip to content

Commit 13a0c85

Browse files
khatwaniNikhilpedja4
authored andcommitted
BAEL-531: Hello World -Spring AMQP Project (eugenp#945)
* BAEL-531: Hello World -Spring AMQP Project * Review Comments
1 parent 60da0a9 commit 13a0c85

4 files changed

Lines changed: 100 additions & 0 deletions

File tree

‎spring-amqp/pom.xml‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>com.baeldung</groupId>
6+
<artifactId>springamqp</artifactId>
7+
<version>0.1-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<name>springamqp</name>
11+
<description>Introduction to Spring-AMQP</description>
12+
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
16+
</properties>
17+
18+
<dependencies>
19+
<dependency>
20+
<groupId>org.springframework.amqp</groupId>
21+
<artifactId>spring-rabbit</artifactId>
22+
<version>1.6.6.RELEASE</version>
23+
</dependency>
24+
</dependencies>
25+
26+
<build>
27+
<finalName>springamqp</finalName>
28+
<plugins>
29+
<plugin>
30+
<groupId>org.apache.maven.plugins</groupId>
31+
<artifactId>maven-compiler-plugin</artifactId>
32+
<version>${maven-compiler-plugin.version}</version>
33+
<configuration>
34+
<source>1.8</source>
35+
<target>1.8</target>
36+
<verbose>true</verbose>
37+
</configuration>
38+
</plugin>
39+
</plugins>
40+
</build>
41+
</project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.baeldung.springamqp.consumer;
2+
3+
public class Consumer {
4+
public void listen(String foo) {
5+
System.out.println(foo);
6+
}
7+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.baeldung.springamqp.producer;
2+
3+
import org.springframework.amqp.core.AmqpTemplate;
4+
import org.springframework.amqp.rabbit.core.RabbitTemplate;
5+
import org.springframework.context.support.AbstractApplicationContext;
6+
import org.springframework.context.support.ClassPathXmlApplicationContext;
7+
8+
public class Producer {
9+
10+
public static void main(String[] args) throws InterruptedException {
11+
AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
12+
AmqpTemplate template = ctx.getBean(RabbitTemplate.class);
13+
template.convertAndSend("Hello, world!");
14+
Thread.sleep(1000);
15+
ctx.destroy();
16+
}
17+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
4+
xmlns:p="http://www.springframework.org/schema/p" xmlns:rabbit="http://www.springframework.org/schema/rabbit"
5+
xmlns:c="http://www.springframework.org/schema/c" xmlns:util="http://www.springframework.org/schema/util"
6+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
7+
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
8+
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
9+
http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit-1.4.xsd">
10+
11+
<rabbit:connection-factory id="connectionFactory" host="localhost" username="guest" password="guest" />
12+
13+
<rabbit:template id="amqpTemplate" connection-factory="connectionFactory"
14+
exchange="myExchange" routing-key="foo.bar" />
15+
16+
<rabbit:admin connection-factory="connectionFactory" />
17+
18+
<rabbit:queue name="myQueue" />
19+
20+
<rabbit:topic-exchange name="myExchange">
21+
<rabbit:bindings>
22+
<rabbit:binding queue="myQueue" pattern="foo.*" />
23+
</rabbit:bindings>
24+
</rabbit:topic-exchange>
25+
26+
27+
<rabbit:listener-container
28+
connection-factory="connectionFactory">
29+
<rabbit:listener ref="consumer" method="listen"
30+
queue-names="myQueue" />
31+
</rabbit:listener-container>
32+
33+
<bean id="consumer" class="com.baeldung.springamqp.consumer.Consumer" />
34+
35+
</beans>

0 commit comments

Comments
 (0)