Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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:rabbit="http://www.springframework.org/schema/rabbit"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
- http://www.springframework.org/schema/rabbit
- http://www.springframework.org/schema/rabbit/spring-rabbit-1.0.xsd">
- <rabbit:connection-factory id="connectionFactory"
- host="localhost" username="guest" password="guest"/>
- <rabbit:admin connection-factory="connectionFactory"/>
- <rabbit:template id="amqpTemplate" connection-factory="connectionFactory"
- exchange="tpExchange"/>
- </beans>
- public class SpringAMQPRabbitSender {
- private final static String SENDER_XML = "springamqp-rabbit-sender- context.xml";
- public static void main(String[] args) throws Exception {
- AmqpTemplate amqpTemplate = (AmqpTemplate)(new ClassPathXmlApplicationContext(SENDER_XML)).getBean("amqpTemplate");
- int messagCount = 0;
- while (messagCount < 10){
- amqpTemplate.convertAndSend("tp.routingkey.1", "Message # " + messagCount++);
- }
- System.out.println( messagCount + " message(s) sent successfully.");
- }
- <?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:rabbit="http://www.springframework.org/schema/rabbit"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
- http://www.springframework.org/schema/rabbit
- http://www.springframework.org/schema/rabbit/spring-rabbit-1.0.xsd">
- <rabbit:connection-factory id="connectionFactory" host="localhost"
- username="guest" password="guest"/>
- <rabbit:admin connection-factory="connectionFactory"/>
- <rabbit:queue id ="tpQueue"/>
- <rabbit:topic-exchange id="tpExchange" name="tpExchange">
- <rabbit:bindings>
- <rabbit:binding queue="tpQueue" pattern="tp.routingkey.1">
- </rabbit:binding>
- </rabbit:bindings>
- </rabbit:topic-exchange>
- <bean id="asyncListener" class="com.tp.spring_amqp_rabbitmq.SpringAMQPRabbitAyncListener"/>
- <rabbit:listener-container id="myListenerContainer" connection-factory="connectionFactory">
- <rabbit:listener ref="asyncListener" queue-names="tpQueue"/>
- </rabbit:listener-container>
- </beans>
Add Comment
Please, Sign In to add comment