BAEL-531: Hello World -Spring AMQP Project (#945)
* BAEL-531: Hello World -Spring AMQP Project * Review Comments
This commit is contained in:
parent
60da0a9542
commit
13a0c859bd
|
@ -0,0 +1,41 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>springamqp</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>springamqp</name>
|
||||
<description>Introduction to Spring-AMQP</description>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.amqp</groupId>
|
||||
<artifactId>spring-rabbit</artifactId>
|
||||
<version>1.6.6.RELEASE</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>springamqp</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${maven-compiler-plugin.version}</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<verbose>true</verbose>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,7 @@
|
|||
package com.baeldung.springamqp.consumer;
|
||||
|
||||
public class Consumer {
|
||||
public void listen(String foo) {
|
||||
System.out.println(foo);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:p="http://www.springframework.org/schema/p" xmlns:rabbit="http://www.springframework.org/schema/rabbit"
|
||||
xmlns:c="http://www.springframework.org/schema/c" xmlns:util="http://www.springframework.org/schema/util"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
|
||||
http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit-1.4.xsd">
|
||||
|
||||
<rabbit:connection-factory id="connectionFactory" host="localhost" username="guest" password="guest" />
|
||||
|
||||
<rabbit:template id="amqpTemplate" connection-factory="connectionFactory"
|
||||
exchange="myExchange" routing-key="foo.bar" />
|
||||
|
||||
<rabbit:admin connection-factory="connectionFactory" />
|
||||
|
||||
<rabbit:queue name="myQueue" />
|
||||
|
||||
<rabbit:topic-exchange name="myExchange">
|
||||
<rabbit:bindings>
|
||||
<rabbit:binding queue="myQueue" pattern="foo.*" />
|
||||
</rabbit:bindings>
|
||||
</rabbit:topic-exchange>
|
||||
|
||||
|
||||
<rabbit:listener-container
|
||||
connection-factory="connectionFactory">
|
||||
<rabbit:listener ref="consumer" method="listen"
|
||||
queue-names="myQueue" />
|
||||
</rabbit:listener-container>
|
||||
|
||||
<bean id="consumer" class="com.baeldung.springamqp.consumer.Consumer" />
|
||||
|
||||
</beans>
|
Loading…
Reference in New Issue