Maven引入相关jar
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
<version>3.2.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-amqp</artifactId>
<version>2.1.3.RELEASE</version>
</dependency>
spring-mq.xml
<?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:rabbit="http://www.springframework.org/schema/rabbit"
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.xsd
http://www.springframework.org/schema/rabbit
http://www.springframework.org/schema/rabbit/spring-rabbit-1.0.xsd">
<context:property-placeholder location="classpath:jdbc.properties,classpath:config.properties" />
<bean />
</rabbit:listener-container>
</beans>
生产者
public void thrwosmq(){
amqpTemplate.convertAndSend("jimmy-request-queue","ddd");
System.out.println("asdf");
}
消费者
public class Foo {
public void handleRequestMessage(String aaa) {
System.out.println(aaa);
}
}