当前位置:   article > 正文

RabbitMQ for Spring XML Say Hello的使用 (六)_rabbirmq3.6.5的maven依赖xml

rabbirmq3.6.5的maven依赖xml

  环境信息

JDK 版本 :1.7

RabbiMQ 服务端版本:3.8.8

erlang版本:Erlang 23.3.4.7

一、maven 依赖文件

  1. <dependency>
  2. <groupId>org.springframework</groupId>
  3. <artifactId>spring-core</artifactId>
  4. <version>4.3.19.RELEASE</version>
  5. <exclusions>
  6. <exclusion>
  7. <groupId>commons-logging</groupId>
  8. <artifactId>commons-logging</artifactId>
  9. </exclusion>
  10. </exclusions>
  11. </dependency>
  12. <dependency>
  13. <groupId>org.slf4j</groupId>
  14. <artifactId>jcl-over-slf4j</artifactId>
  15. <version>1.7.21</version>
  16. </dependency>
  17. <dependency>
  18. <groupId>ch.qos.logback</groupId>
  19. <artifactId>logback-classic</artifactId>
  20. <version>1.1.7</version>
  21. </dependency>
  22. <dependency>
  23. <groupId>org.springframework</groupId>
  24. <artifactId>spring-context</artifactId>
  25. <version>4.3.19.RELEASE</version>
  26. </dependency>
  27. <dependency>
  28. <groupId>org.springframework.amqp</groupId>
  29. <artifactId>spring-rabbit</artifactId>
  30. <version>1.7.10.RELEASE</version>
  31. </dependency>
  32. <dependency>
  33. <groupId>junit</groupId>
  34. <artifactId>junit</artifactId>
  35. <version>4.11</version>
  36. <scope>test</scope>
  37. </dependency>

二、使用步骤

1. 存spring 版实现配置文件  和下面的 rabbit-spring 配置形成对比

  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. xmlns:util="http://www.springframework.org/schema/util"
  6. xsi:schemaLocation="http://www.springframework.org/schema/rabbit
  7. http://www.springframework.org/schema/rabbit/spring-rabbit.xsd
  8. http://www.springframework.org/schema/util
  9. http://www.springframework.org/schema/util/spring-util.xsd
  10. http://www.springframework.org/schema/beans
  11. http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">
  12. <description>spring 版配置</description>
  13. <!-- 创建rabbitmq连接对象 连接方式一 -->
  14. <bean id="connectionFactory" class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory">
  15. <!-- 构造函数注入的方式注入 IP 和 端口号
  16. <constructor-arg name="hostname" value="192.168.10.222" />
  17. <constructor-arg name="port" value="5672" /> -->
  18. <!-- 访问ip -->
  19. <property name="host" value="192.168.10.222"></property>
  20. <!-- 端口 -->
  21. <property name="port" value="5672"></property>
  22. <!-- 访问账户信息 -->
  23. <property name="username" value="julong" />
  24. <property name="password" value="julong" />
  25. <!-- 虚拟主机 -->
  26. <property name="virtualHost" value="/" />
  27. <!-- 缓存模式 CHANNEL CONNECTION 默认 CHANNEL-->
  28. <property name="cacheMode" value="CHANNEL"></property>
  29. <!-- 默认通道缓存 25 -->
  30. <property name="channelCacheSize" value="25"></property>
  31. <!-- 连接最大数 默认 是 2的31次方-1 -->
  32. <property name="connectionLimit" value="20"></property>
  33. </bean>
  34. <!-- 指定admin 信息 自动生成 相关 主题 交换机 队列 -->
  35. <bean id="rabbitAdmin" class="org.springframework.amqp.rabbit.core.RabbitAdmin">
  36. <constructor-arg name="connectionFactory" ref="connectionFactory"></constructor-arg>
  37. </bean>
  38. <!-- 定义队列信息 队列一定要指定名称 否则会报错 下面的引用 检测不到对应的 队列 -->
  39. <bean id="springTestQueue" name="spring-test-queue" class="org.springframework.amqp.core.Queue" >
  40. <!-- 队列名称 -->
  41. <constructor-arg name="name" value="spring-test-queue"></constructor-arg>
  42. <!-- 是否自动删除 -->
  43. <constructor-arg name="autoDelete" value="false"></constructor-arg>
  44. <!-- 是否持久化 -->
  45. <constructor-arg name="durable" value="true"></constructor-arg>
  46. <!-- 是否只能被声明者使用 -->
  47. <constructor-arg name="exclusive" value="false"></constructor-arg>
  48. <!-- 是都自动生成此对象 -->
  49. <property name="shouldDeclare" value="true"></property>
  50. </bean>
  51. <!-- 配置交换机 -->
  52. <bean id="directExchange" name="spring-test-exchange" class="org.springframework.amqp.core.DirectExchange">
  53. <!-- 交换机名称 -->
  54. <constructor-arg name="name" value="spring-test-exchange"></constructor-arg>
  55. <!-- 是否自动删除 -->
  56. <constructor-arg name="autoDelete" value="true"></constructor-arg>
  57. <!-- 是否持久化 -->
  58. <constructor-arg name="durable" value="true"></constructor-arg>
  59. </bean>
  60. <!-- 参数map 这个需要声明 绑定交换机的时候 必须输入这个参数 因为 它存在于构造函数中 会自动的解析 -->
  61. <bean id="arguments" class="java.util.HashMap"/>
  62. <!-- 绑定队列和交换机 -->
  63. <bean id="binding" class="org.springframework.amqp.core.Binding">
  64. <!-- 目的地 队列名 -->
  65. <constructor-arg name="destination" value="spring-test-queue"></constructor-arg>
  66. <!-- 目的类型 -->
  67. <constructor-arg name="destinationType" value="QUEUE"></constructor-arg>
  68. <!-- 交换机名称 -->
  69. <constructor-arg name="exchange" value="spring-test-exchange"></constructor-arg>
  70. <!-- 关键字 -->
  71. <constructor-arg name="routingKey" value="*-test-*"></constructor-arg>
  72. <!-- 自定义参数 -->
  73. <constructor-arg name="arguments" ref="arguments"></constructor-arg>
  74. </bean>
  75. <!-- 定义消息模板 -->
  76. <bean id="rabbitTemplate" class="org.springframework.amqp.rabbit.core.RabbitTemplate">
  77. <!-- 连接工厂 -->
  78. <property name="connectionFactory" ref="connectionFactory"></property>
  79. <!-- 交换机名称 -->
  80. <property name="exchange" value="spring-test-exchange"></property>
  81. </bean>
  82. <!-- 配置需要监听的类 -->
  83. <bean id="messageConsumer" class="com.julong.spring.consumer.MessageConsumer">
  84. </bean>
  85. <!-- 定义监听对象 -->
  86. <bean id="messageListenerAdapter" class="org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter">
  87. <property name="delegate" ref="messageConsumer"></property>
  88. <property name="defaultListenerMethod" value="onMessage"></property>
  89. <!-- <property name="responseExchange" value="spring-test-exchange"></property> -->
  90. </bean>
  91. <!-- 定义监听容器 -->
  92. <bean class="org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer">
  93. <property name="connectionFactory" ref="connectionFactory"></property>
  94. <property name="messageListener" ref="messageListenerAdapter"></property>
  95. <property name="queues" ref="springTestQueue"></property>
  96. <property name="rabbitAdmin" ref="rabbitAdmin"></property>
  97. </bean>
  98. </beans>

2.spring-rabbit版配置文件 和上边的 存spring版配置形成对比

  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. xmlns:util="http://www.springframework.org/schema/util"
  6. xsi:schemaLocation="http://www.springframework.org/schema/rabbit
  7. http://www.springframework.org/schema/rabbit/spring-rabbit.xsd
  8. http://www.springframework.org/schema/util
  9. http://www.springframework.org/schema/util/spring-util.xsd
  10. http://www.springframework.org/schema/beans
  11. http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">
  12. <description>rabbitmq版配置</description>
  13. <!-- 连接方式二 配置连接
  14. id : 编号
  15. host: 连接地址
  16. port: 端口
  17. username: 连接名称
  18. password: 密码
  19. virtual-host: 虚拟主机
  20. connection-limit:最大连接数
  21. cache-mode 缓存类型
  22. -->
  23. <rabbit:connection-factory id="connectionFactory"
  24. host="192.168.10.222" port="5672"
  25. username="julong" password="julong"
  26. virtual-host="/"
  27. connection-limit="25" cache-mode="CHANNEL" />
  28. <!-- 通过指定下面的admin信息,当前producer中的exchange和queue会在rabbitmq服务器上自动生成
  29. id: 编号
  30. connection-factory: 连接工厂
  31. auto-startup:是否自动启动
  32. -->
  33. <rabbit:admin id="rabbitAdmin" connection-factory="connectionFactory" auto-startup="true" />
  34. <!-- 创建队列
  35. id: 编号
  36. name:队列名称
  37. auto-delete:是否自动删除
  38. durable:是否持久化
  39. -->
  40. <rabbit:queue id="springTestQueue" name="spring-test-queue" auto-delete="false" durable="true" declared-by="rabbitAdmin" />
  41. <!-- 绑定交换机
  42. id: 交换机名称
  43. name:交换机名称
  44. -->
  45. <rabbit:direct-exchange id="directExchange" name="spring-test-exchange" auto-delete="true" declared-by="rabbitAdmin">
  46. <rabbit:bindings>
  47. <!-- 绑定交换机
  48. queue:队列名称
  49. key:路由键
  50. -->
  51. <rabbit:binding queue="spring-test-queue" key="" />
  52. </rabbit:bindings>
  53. </rabbit:direct-exchange>
  54. <!-- 定义消息接收发送模板类
  55. id:编号标识
  56. connection-factory:连接工厂
  57. exchange:交换机
  58. -->
  59. <rabbit:template id="rabbitmqTemplate" connection-factory="connectionFactory" exchange="spring-test-exchange" />
  60. </beans>

3.客户端实现类:此类对应 存spring版配置的注解类

  1. package com.julong.spring.consumer;
  2. /**
  3. * 客户端消息接收类
  4. * @author julong
  5. * @date 2022年1月23日 下午2:44:11
  6. * @desc
  7. */
  8. public class MessageConsumer{
  9. public void onMessage(String message) {
  10. // TODO Auto-generated method stub
  11. System.out.println("客户端发送的消息是:"+message);
  12. }
  13. }

spring总配置

  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. xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">
  6. <!-- 引入配置文件 -->
  7. <!-- spring版配置 -->
  8. <import resource="applicationContext-rabbitmq-spring.xml" />
  9. <!-- rabbit版配置 -->
  10. <!-- <import resource="applicationContext-rabbitmq.xml" /> -->
  11. </beans>

启动类:

  1. package com.julong;
  2. import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
  3. import org.springframework.amqp.rabbit.core.RabbitAdmin;
  4. import org.springframework.amqp.rabbit.core.RabbitTemplate;
  5. import org.springframework.context.ApplicationContext;
  6. import org.springframework.context.support.FileSystemXmlApplicationContext;
  7. /**
  8. * spring 启动类
  9. * @author julong
  10. * @date 2022年1月20日 上午10:37:20
  11. * @desc
  12. */
  13. public class SpringApplicationStartMain {
  14. public static void main( String[] args ) {
  15. ApplicationContext context = new FileSystemXmlApplicationContext("classpath:applicationContext.xml");
  16. CachingConnectionFactory factory = (CachingConnectionFactory) context.getBean("connectionFactory");
  17. System.out.println("rabbitmq连接信息"+factory.toString());
  18. RabbitAdmin rabbitAdmin = (RabbitAdmin) context.getBean("rabbitAdmin");
  19. System.out.println("rabbitAdmin管理信息"+rabbitAdmin);
  20. RabbitTemplate rabbitTemplate = (RabbitTemplate) context.getBean("rabbitTemplate");
  21. System.out.println("rabbitTemplate模板信息"+rabbitTemplate);
  22. for (int i = 0; i < 10; i++) {
  23. rabbitTemplate.convertAndSend("spring-test-queue","spring to hello rabbitmq!"+System.currentTimeMillis());
  24. System.out.println("消息发送成功");
  25. try {
  26. Thread.sleep(1000);
  27. } catch (InterruptedException e) {
  28. // TODO Auto-generated catch block
  29. e.printStackTrace();
  30. }
  31. }
  32. // Message message = rabbitTemplate.receive("spring-test-queue");
  33. // try {
  34. // if(null != message){
  35. // System.out.println("接收到发送的消息是:"+new String(message.getBody(), "utf-8"));
  36. // }
  37. // } catch (UnsupportedEncodingException e) {
  38. // // TODO Auto-generated catch block
  39. // e.printStackTrace();
  40. // }
  41. }
  42. }

结果

服务端:

  1. 14:54:17.124 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] INFO o.s.a.r.c.CachingConnectionFactory - Created new connection: connectionFactory#4be021db:0/SimpleConnection@5e232a3e [delegate=amqp://julong@192.168.10.222:5672/, localPort= 52327]
  2. 14:54:17.124 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] TRACE o.s.retry.support.RetryTemplate - RetryContext retrieved: [RetryContext: count=0, lastException=null, exhausted=false]
  3. 14:54:17.124 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] DEBUG o.s.retry.support.RetryTemplate - Retry: count=0
  4. 14:54:17.124 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] DEBUG o.s.amqp.rabbit.core.RabbitAdmin - Initializing declarations
  5. 14:54:17.134 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'directExchange'
  6. 14:54:17.134 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'springTestQueue'
  7. 14:54:17.134 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'binding'
  8. 14:54:17.134 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] INFO o.s.amqp.rabbit.core.RabbitAdmin - Auto-declaring a non-durable or auto-delete Exchange (spring-test-exchange) durable:true, auto-delete:true. It will be deleted by the broker if it shuts down, and can be redeclared by closing and reopening the connection.
  9. 14:54:17.144 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] DEBUG o.s.a.r.c.CachingConnectionFactory - Creating cached Rabbit Channel from AMQChannel(amqp://julong@192.168.10.222:5672/,1)
  10. 14:54:17.164 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] DEBUG o.s.amqp.rabbit.core.RabbitTemplate - Executing callback on RabbitMQ Channel: Cached Rabbit Channel: AMQChannel(amqp://julong@192.168.10.222:5672/,1), conn: Proxy@44b57604 Shared Rabbit Connection: SimpleConnection@5e232a3e [delegate=amqp://julong@192.168.10.222:5672/, localPort= 52327]
  11. 14:54:17.174 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] DEBUG o.s.amqp.rabbit.core.RabbitAdmin - declaring Exchange 'spring-test-exchange'
  12. 14:54:17.174 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] TRACE o.s.a.r.c.CachingConnectionFactory - AMQChannel(amqp://julong@192.168.10.222:5672/,1) channel.exchangeDeclare([spring-test-exchange, direct, true, true, false, {}])
  13. 14:54:17.174 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] DEBUG o.s.amqp.rabbit.core.RabbitAdmin - declaring Queue 'spring-test-queue'
  14. 14:54:17.174 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] TRACE o.s.a.r.c.CachingConnectionFactory - AMQChannel(amqp://julong@192.168.10.222:5672/,1) channel.queueDeclare([spring-test-queue, true, false, false, null])
  15. 14:54:17.174 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] DEBUG o.s.amqp.rabbit.core.RabbitAdmin - Binding destination [spring-test-queue (QUEUE)] to exchange [spring-test-exchange] with routing key [*-test-*]
  16. 14:54:17.174 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] TRACE o.s.a.r.c.CachingConnectionFactory - AMQChannel(amqp://julong@192.168.10.222:5672/,1) channel.queueBind([spring-test-queue, spring-test-exchange, *-test-*, {}])
  17. 14:54:17.184 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] TRACE o.s.a.r.c.CachingConnectionFactory - AMQChannel(amqp://julong@192.168.10.222:5672/,1) channel.close()
  18. 14:54:17.184 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] TRACE o.s.a.r.c.CachingConnectionFactory - Returning cached Channel: AMQChannel(amqp://julong@192.168.10.222:5672/,1)
  19. 14:54:17.184 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] DEBUG o.s.amqp.rabbit.core.RabbitAdmin - Declarations finished
  20. 14:54:17.184 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] TRACE o.s.a.r.c.CachingConnectionFactory - Cached Rabbit Channel: AMQChannel(amqp://julong@192.168.10.222:5672/,1), conn: Proxy@44b57604 Shared Rabbit Connection: SimpleConnection@5e232a3e [delegate=amqp://julong@192.168.10.222:5672/, localPort= 52327] retrieved from cache
  21. 14:54:17.184 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] TRACE o.s.a.r.c.CachingConnectionFactory - AMQChannel(amqp://julong@192.168.10.222:5672/,1) channel.isOpen()
  22. 14:54:17.184 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] TRACE o.s.a.r.c.CachingConnectionFactory - Found cached Rabbit Channel: Cached Rabbit Channel: AMQChannel(amqp://julong@192.168.10.222:5672/,1), conn: Proxy@44b57604 Shared Rabbit Connection: SimpleConnection@5e232a3e [delegate=amqp://julong@192.168.10.222:5672/, localPort= 52327]
  23. 14:54:17.184 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] DEBUG o.s.amqp.rabbit.core.RabbitTemplate - Executing callback on RabbitMQ Channel: Cached Rabbit Channel: AMQChannel(amqp://julong@192.168.10.222:5672/,1), conn: Proxy@44b57604 Shared Rabbit Connection: SimpleConnection@5e232a3e [delegate=amqp://julong@192.168.10.222:5672/, localPort= 52327]
  24. 14:54:17.184 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] TRACE o.s.a.r.c.CachingConnectionFactory - AMQChannel(amqp://julong@192.168.10.222:5672/,1) channel.queueDeclarePassive([spring-test-queue])
  25. 14:54:17.184 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] TRACE o.s.a.r.c.CachingConnectionFactory - AMQChannel(amqp://julong@192.168.10.222:5672/,1) channel.close()
  26. 14:54:17.184 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] TRACE o.s.a.r.c.CachingConnectionFactory - Returning cached Channel: AMQChannel(amqp://julong@192.168.10.222:5672/,1)
  27. 14:54:17.184 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] DEBUG o.s.a.r.l.BlockingQueueConsumer - Starting consumer Consumer@9353778: tags=[{}], channel=null, acknowledgeMode=AUTO local queue size=0
  28. 14:54:17.194 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] TRACE o.s.a.r.c.CachingConnectionFactory - Cached Rabbit Channel: AMQChannel(amqp://julong@192.168.10.222:5672/,1), conn: Proxy@44b57604 Shared Rabbit Connection: SimpleConnection@5e232a3e [delegate=amqp://julong@192.168.10.222:5672/, localPort= 52327] retrieved from cache
  29. 14:54:17.194 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] TRACE o.s.a.r.c.CachingConnectionFactory - AMQChannel(amqp://julong@192.168.10.222:5672/,1) channel.isOpen()
  30. 14:54:17.194 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] TRACE o.s.a.r.c.CachingConnectionFactory - Found cached Rabbit Channel: Cached Rabbit Channel: AMQChannel(amqp://julong@192.168.10.222:5672/,1), conn: Proxy@44b57604 Shared Rabbit Connection: SimpleConnection@5e232a3e [delegate=amqp://julong@192.168.10.222:5672/, localPort= 52327]
  31. 14:54:17.194 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] TRACE o.s.a.r.c.CachingConnectionFactory - AMQChannel(amqp://julong@192.168.10.222:5672/,1) channel.getTargetChannel()
  32. 14:54:17.194 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] TRACE o.s.a.r.c.CachingConnectionFactory - AMQChannel(amqp://julong@192.168.10.222:5672/,1) channel.queueDeclarePassive([spring-test-queue])
  33. 14:54:17.204 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] TRACE o.s.a.r.c.CachingConnectionFactory - AMQChannel(amqp://julong@192.168.10.222:5672/,1) channel.basicQos([1])
  34. 14:54:17.204 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] TRACE o.s.a.r.c.CachingConnectionFactory - AMQChannel(amqp://julong@192.168.10.222:5672/,1) channel.basicConsume([spring-test-queue, false, , false, false, {}, ConsumerDecorator{queue='spring-test-queue', consumerTag='null'}])
  35. 14:54:17.214 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] DEBUG o.s.a.r.l.BlockingQueueConsumer - Started on queue 'spring-test-queue' with tag amq.ctag-vdxOCAiZ8UG905Agh86oKw: Consumer@9353778: tags=[{amq.ctag-vdxOCAiZ8UG905Agh86oKw=spring-test-queue}], channel=Cached Rabbit Channel: AMQChannel(amqp://julong@192.168.10.222:5672/,1), conn: Proxy@44b57604 Shared Rabbit Connection: SimpleConnection@5e232a3e [delegate=amqp://julong@192.168.10.222:5672/, localPort= 52327], acknowledgeMode=AUTO local queue size=0
  36. 14:54:17.214 [main] DEBUG o.s.c.s.DefaultLifecycleProcessor - Successfully started bean 'org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0'
  37. 14:54:17.214 [main] TRACE o.s.c.s.FileSystemXmlApplicationContext - Publishing event in org.springframework.context.support.FileSystemXmlApplicationContext@36d64342: org.springframework.context.event.ContextRefreshedEvent[source=org.springframework.context.support.FileSystemXmlApplicationContext@36d64342: startup date [Sun Jan 23 14:54:16 CST 2022]; root of context hierarchy]
  38. 14:54:17.214 [main] TRACE o.s.c.e.PropertySourcesPropertyResolver - Searching for key 'spring.liveBeansView.mbeanDomain' in PropertySource 'systemProperties'
  39. 14:54:17.214 [main] TRACE o.s.c.e.PropertySourcesPropertyResolver - Searching for key 'spring.liveBeansView.mbeanDomain' in PropertySource 'systemEnvironment'
  40. 14:54:17.214 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Could not find key 'spring.liveBeansView.mbeanDomain' in any property source
  41. 14:54:17.214 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'connectionFactory'
  42. rabbitmq连接信息CachingConnectionFactory [channelCacheSize=25, host=192.168.10.222, port=5672, active=true connectionFactory]
  43. 14:54:17.214 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'rabbitAdmin'
  44. rabbitAdmin管理信息org.springframework.amqp.rabbit.core.RabbitAdmin@2145b572
  45. 14:54:17.214 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'rabbitTemplate'
  46. rabbitTemplate模板信息org.springframework.amqp.rabbit.core.RabbitTemplate@39529185
  47. 14:54:17.224 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] TRACE o.s.a.r.l.SimpleMessageListenerContainer - Waiting for message from consumer.
  48. 14:54:17.224 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] DEBUG o.s.a.r.l.BlockingQueueConsumer - Retrieving delivery for Consumer@9353778: tags=[{amq.ctag-vdxOCAiZ8UG905Agh86oKw=spring-test-queue}], channel=Cached Rabbit Channel: AMQChannel(amqp://julong@192.168.10.222:5672/,1), conn: Proxy@44b57604 Shared Rabbit Connection: SimpleConnection@5e232a3e [delegate=amqp://julong@192.168.10.222:5672/, localPort= 52327], acknowledgeMode=AUTO local queue size=0
  49. 14:54:17.224 [pool-1-thread-3] DEBUG o.s.a.r.l.BlockingQueueConsumer - ConsumeOK: Consumer@9353778: tags=[{amq.ctag-vdxOCAiZ8UG905Agh86oKw=spring-test-queue}], channel=Cached Rabbit Channel: AMQChannel(amqp://julong@192.168.10.222:5672/,1), conn: Proxy@44b57604 Shared Rabbit Connection: SimpleConnection@5e232a3e [delegate=amqp://julong@192.168.10.222:5672/, localPort= 52327], acknowledgeMode=AUTO local queue size=0
  50. 14:54:17.224 [pool-1-thread-3] TRACE o.s.c.s.FileSystemXmlApplicationContext - Publishing event in org.springframework.context.support.FileSystemXmlApplicationContext@36d64342: ConsumeOkEvent [queue=spring-test-queue, consumerTag=amq.ctag-vdxOCAiZ8UG905Agh86oKw, consumer=org.springframework.amqp.rabbit.listener.BlockingQueueConsumer$InternalConsumer@7c892958]
  51. 14:54:17.224 [main] DEBUG o.s.a.r.c.CachingConnectionFactory - Creating cached Rabbit Channel from AMQChannel(amqp://julong@192.168.10.222:5672/,2)
  52. 14:54:17.234 [main] DEBUG o.s.amqp.rabbit.core.RabbitTemplate - Executing callback on RabbitMQ Channel: Cached Rabbit Channel: AMQChannel(amqp://julong@192.168.10.222:5672/,2), conn: Proxy@44b57604 Shared Rabbit Connection: SimpleConnection@5e232a3e [delegate=amqp://julong@192.168.10.222:5672/, localPort= 52327]
  53. 14:54:17.234 [main] DEBUG o.s.amqp.rabbit.core.RabbitTemplate - Publishing message on exchange [spring-test-exchange], routingKey = [spring-test-queue]
  54. 14:54:17.234 [main] TRACE o.s.a.r.c.CachingConnectionFactory - AMQChannel(amqp://julong@192.168.10.222:5672/,2) channel.basicPublish([spring-test-exchange, spring-test-queue, false, #contentHeader<basic>(content-type=text/plain, content-encoding=UTF-8, headers={}, delivery-mode=2, priority=0, correlation-id=null, reply-to=null, expiration=null, message-id=null, timestamp=null, type=null, user-id=null, app-id=null, cluster-id=null), [B@291ae])
  55. 14:54:17.234 [main] TRACE o.s.a.r.c.CachingConnectionFactory - AMQChannel(amqp://julong@192.168.10.222:5672/,2) channel.close()
  56. 14:54:17.234 [main] TRACE o.s.a.r.c.CachingConnectionFactory - Returning cached Channel: AMQChannel(amqp://julong@192.168.10.222:5672/,2)
  57. 消息发送成功
  58. 14:54:17.244 [pool-1-thread-4] DEBUG o.s.a.r.l.BlockingQueueConsumer - Storing delivery for consumerTag: 'amq.ctag-vdxOCAiZ8UG905Agh86oKw' with deliveryTag: '1' in Consumer@9353778: tags=[{amq.ctag-vdxOCAiZ8UG905Agh86oKw=spring-test-queue}], channel=Cached Rabbit Channel: AMQChannel(amqp://julong@192.168.10.222:5672/,1), conn: Proxy@44b57604 Shared Rabbit Connection: SimpleConnection@5e232a3e [delegate=amqp://julong@192.168.10.222:5672/, localPort= 52327], acknowledgeMode=AUTO local queue size=0
  59. 14:54:17.244 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] DEBUG o.s.a.r.l.BlockingQueueConsumer - Received message: (Body:'spring to hello rabbitmq!1642920857214' MessageProperties [headers={}, timestamp=null, messageId=null, userId=null, receivedUserId=null, appId=null, clusterId=null, type=null, correlationId=null, correlationIdString=null, replyTo=null, contentType=text/plain, contentEncoding=UTF-8, contentLength=0, deliveryMode=null, receivedDeliveryMode=PERSISTENT, expiration=null, priority=0, redelivered=false, receivedExchange=spring-test-exchange, receivedRoutingKey=spring-test-queue, receivedDelay=null, deliveryTag=1, messageCount=0, consumerTag=amq.ctag-vdxOCAiZ8UG905Agh86oKw, consumerQueue=spring-test-queue])
  60. 客户端发送的消息是:spring to hello rabbitmq!1642920857214
  61. 14:54:17.244 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] TRACE o.s.a.r.l.a.MessageListenerAdapter - No result object given - no result to handle
  62. 14:54:17.244 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] TRACE o.s.a.r.c.CachingConnectionFactory - AMQChannel(amqp://julong@192.168.10.222:5672/,1) channel.basicAck([1, true])
  63. 14:54:17.244 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] TRACE o.s.a.r.l.SimpleMessageListenerContainer - Waiting for message from consumer.
  64. 14:54:17.244 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] DEBUG o.s.a.r.l.BlockingQueueConsumer - Retrieving delivery for Consumer@9353778: tags=[{amq.ctag-vdxOCAiZ8UG905Agh86oKw=spring-test-queue}], channel=Cached Rabbit Channel: AMQChannel(amqp://julong@192.168.10.222:5672/,1), conn: Proxy@44b57604 Shared Rabbit Connection: SimpleConnection@5e232a3e [delegate=amqp://julong@192.168.10.222:5672/, localPort= 52327], acknowledgeMode=AUTO local queue size=0
  65. 14:54:18.234 [main] TRACE o.s.a.r.c.CachingConnectionFactory - Cached Rabbit Channel: AMQChannel(amqp://julong@192.168.10.222:5672/,2), conn: Proxy@44b57604 Shared Rabbit Connection: SimpleConnection@5e232a3e [delegate=amqp://julong@192.168.10.222:5672/, localPort= 52327] retrieved from cache
  66. 14:54:18.234 [main] TRACE o.s.a.r.c.CachingConnectionFactory - AMQChannel(amqp://julong@192.168.10.222:5672/,2) channel.isOpen()
  67. 14:54:18.234 [main] TRACE o.s.a.r.c.CachingConnectionFactory - Found cached Rabbit Channel: Cached Rabbit Channel: AMQChannel(amqp://julong@192.168.10.222:5672/,2), conn: Proxy@44b57604 Shared Rabbit Connection: SimpleConnection@5e232a3e [delegate=amqp://julong@192.168.10.222:5672/, localPort= 52327]
  68. 14:54:18.234 [main] DEBUG o.s.amqp.rabbit.core.RabbitTemplate - Executing callback on RabbitMQ Channel: Cached Rabbit Channel: AMQChannel(amqp://julong@192.168.10.222:5672/,2), conn: Proxy@44b57604 Shared Rabbit Connection: SimpleConnection@5e232a3e [delegate=amqp://julong@192.168.10.222:5672/, localPort= 52327]
  69. 14:54:18.234 [main] DEBUG o.s.amqp.rabbit.core.RabbitTemplate - Publishing message on exchange [spring-test-exchange], routingKey = [spring-test-queue]
  70. 14:54:18.234 [main] TRACE o.s.a.r.c.CachingConnectionFactory - AMQChannel(amqp://julong@192.168.10.222:5672/,2) channel.basicPublish([spring-test-exchange, spring-test-queue, false, #contentHeader<basic>(content-type=text/plain, content-encoding=UTF-8, headers={}, delivery-mode=2, priority=0, correlation-id=null, reply-to=null, expiration=null, message-id=null, timestamp=null, type=null, user-id=null, app-id=null, cluster-id=null), [B@188715b5])
  71. 14:54:18.234 [main] TRACE o.s.a.r.c.CachingConnectionFactory - AMQChannel(amqp://julong@192.168.10.222:5672/,2) channel.close()
  72. 14:54:18.234 [main] TRACE o.s.a.r.c.CachingConnectionFactory - Returning cached Channel: AMQChannel(amqp://julong@192.168.10.222:5672/,2)
  73. 消息发送成功
  74. 14:54:18.234 [pool-1-thread-5] DEBUG o.s.a.r.l.BlockingQueueConsumer - Storing delivery for consumerTag: 'amq.ctag-vdxOCAiZ8UG905Agh86oKw' with deliveryTag: '2' in Consumer@9353778: tags=[{amq.ctag-vdxOCAiZ8UG905Agh86oKw=spring-test-queue}], channel=Cached Rabbit Channel: AMQChannel(amqp://julong@192.168.10.222:5672/,1), conn: Proxy@44b57604 Shared Rabbit Connection: SimpleConnection@5e232a3e [delegate=amqp://julong@192.168.10.222:5672/, localPort= 52327], acknowledgeMode=AUTO local queue size=0
  75. 14:54:18.234 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] DEBUG o.s.a.r.l.BlockingQueueConsumer - Received message: (Body:'spring to hello rabbitmq!1642920858234' MessageProperties [headers={}, timestamp=null, messageId=null, userId=null, receivedUserId=null, appId=null, clusterId=null, type=null, correlationId=null, correlationIdString=null, replyTo=null, contentType=text/plain, contentEncoding=UTF-8, contentLength=0, deliveryMode=null, receivedDeliveryMode=PERSISTENT, expiration=null, priority=0, redelivered=false, receivedExchange=spring-test-exchange, receivedRoutingKey=spring-test-queue, receivedDelay=null, deliveryTag=2, messageCount=0, consumerTag=amq.ctag-vdxOCAiZ8UG905Agh86oKw, consumerQueue=spring-test-queue])
  76. 客户端发送的消息是:spring to hello rabbitmq!1642920858234
  77. 14:54:18.234 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] TRACE o.s.a.r.l.a.MessageListenerAdapter - No result object given - no result to handle
  78. 14:54:18.234 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] TRACE o.s.a.r.c.CachingConnectionFactory - AMQChannel(amqp://julong@192.168.10.222:5672/,1) channel.basicAck([2, true])
  79. 14:54:18.234 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] TRACE o.s.a.r.l.SimpleMessageListenerContainer - Waiting for message from consumer.
  80. 14:54:18.234 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] DEBUG o.s.a.r.l.BlockingQueueConsumer - Retrieving delivery for Consumer@9353778: tags=[{amq.ctag-vdxOCAiZ8UG905Agh86oKw=spring-test-queue}], channel=Cached Rabbit Channel: AMQChannel(amqp://julong@192.168.10.222:5672/,1), conn: Proxy@44b57604 Shared Rabbit Connection: SimpleConnection@5e232a3e [delegate=amqp://julong@192.168.10.222:5672/, localPort= 52327], acknowledgeMode=AUTO local queue size=0

此处只做了一个简单的示例 客户端和服务端在一个工程中

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/139228?site
推荐阅读
相关标签
  

闽ICP备14008679号