Guest User

Untitled

a guest
Feb 26th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  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"
  4. xmlns:rabbit="http://www.springframework.org/schema/rabbit"
  5. xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
  7. http://www.springframework.org/schema/rabbit
  8. http://www.springframework.org/schema/rabbit/spring-rabbit-1.0.xsd">
  9.  
  10. <rabbit:connection-factory id="connectionFactory"
  11. host="localhost" username="guest" password="guest"/>
  12.  
  13. <rabbit:admin connection-factory="connectionFactory"/>
  14.  
  15. <rabbit:template id="amqpTemplate" connection-factory="connectionFactory"
  16. exchange="tpExchange"/>
  17. </beans>
  18.  
  19. public class SpringAMQPRabbitSender {
  20. private final static String SENDER_XML = "springamqp-rabbit-sender- context.xml";
  21. public static void main(String[] args) throws Exception {
  22. AmqpTemplate amqpTemplate = (AmqpTemplate)(new ClassPathXmlApplicationContext(SENDER_XML)).getBean("amqpTemplate");
  23. int messagCount = 0;
  24. while (messagCount < 10){
  25. amqpTemplate.convertAndSend("tp.routingkey.1", "Message # " + messagCount++);
  26. }
  27. System.out.println( messagCount + " message(s) sent successfully.");
  28. }
  29.  
  30. <?xml version="1.0" encoding="utf-8" ?>
  31. <beans xmlns="http://www.springframework.org/schema/beans"
  32. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  33. xmlns:rabbit="http://www.springframework.org/schema/rabbit"
  34. xsi:schemaLocation="http://www.springframework.org/schema/beans
  35. http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
  36. http://www.springframework.org/schema/rabbit
  37. http://www.springframework.org/schema/rabbit/spring-rabbit-1.0.xsd">
  38.  
  39. <rabbit:connection-factory id="connectionFactory" host="localhost"
  40. username="guest" password="guest"/>
  41.  
  42. <rabbit:admin connection-factory="connectionFactory"/>
  43. <rabbit:queue id ="tpQueue"/>
  44.  
  45. <rabbit:topic-exchange id="tpExchange" name="tpExchange">
  46. <rabbit:bindings>
  47. <rabbit:binding queue="tpQueue" pattern="tp.routingkey.1">
  48. </rabbit:binding>
  49. </rabbit:bindings>
  50. </rabbit:topic-exchange>
  51.  
  52. <bean id="asyncListener" class="com.tp.spring_amqp_rabbitmq.SpringAMQPRabbitAyncListener"/>
  53.  
  54. <rabbit:listener-container id="myListenerContainer" connection-factory="connectionFactory">
  55. <rabbit:listener ref="asyncListener" queue-names="tpQueue"/>
  56. </rabbit:listener-container>
  57.  
  58. </beans>
Add Comment
Please, Sign In to add comment