赞
踩
JDK 版本 :1.7
RabbiMQ 服务端版本:3.8.8
erlang版本:Erlang 23.3.4.7
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-core</artifactId>
- <version>4.3.19.RELEASE</version>
- <exclusions>
- <exclusion>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>jcl-over-slf4j</artifactId>
- <version>1.7.21</version>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- <version>1.1.7</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-context</artifactId>
- <version>4.3.19.RELEASE</version>
- </dependency>
-
-
- <dependency>
- <groupId>org.springframework.amqp</groupId>
- <artifactId>spring-rabbit</artifactId>
- <version>1.7.10.RELEASE</version>
- </dependency>
-
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.11</version>
- <scope>test</scope>
- </dependency>
- <?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"
- xmlns:util="http://www.springframework.org/schema/util"
- xsi:schemaLocation="http://www.springframework.org/schema/rabbit
- http://www.springframework.org/schema/rabbit/spring-rabbit.xsd
- http://www.springframework.org/schema/util
- http://www.springframework.org/schema/util/spring-util.xsd
- http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">
- <description>spring 版配置</description>
- <!-- 创建rabbitmq连接对象 连接方式一 -->
- <bean id="connectionFactory" class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory">
- <!-- 构造函数注入的方式注入 IP 和 端口号
- <constructor-arg name="hostname" value="192.168.10.222" />
- <constructor-arg name="port" value="5672" /> -->
- <!-- 访问ip -->
- <property name="host" value="192.168.10.222"></property>
- <!-- 端口 -->
- <property name="port" value="5672"></property>
- <!-- 访问账户信息 -->
- <property name="username" value="julong" />
- <property name="password" value="julong" />
- <!-- 虚拟主机 -->
- <property name="virtualHost" value="/" />
- <!-- 缓存模式 CHANNEL CONNECTION 默认 CHANNEL-->
- <property name="cacheMode" value="CHANNEL"></property>
- <!-- 默认通道缓存 25 -->
- <property name="channelCacheSize" value="25"></property>
- <!-- 连接最大数 默认 是 2的31次方-1 -->
- <property name="connectionLimit" value="20"></property>
- </bean>
- <!-- 指定admin 信息 自动生成 相关 主题 交换机 队列 -->
- <bean id="rabbitAdmin" class="org.springframework.amqp.rabbit.core.RabbitAdmin">
- <constructor-arg name="connectionFactory" ref="connectionFactory"></constructor-arg>
- </bean>
- <!-- 定义队列信息 队列一定要指定名称 否则会报错 下面的引用 检测不到对应的 队列 -->
- <bean id="springTestQueue" name="spring-test-queue" class="org.springframework.amqp.core.Queue" >
- <!-- 队列名称 -->
- <constructor-arg name="name" value="spring-test-queue"></constructor-arg>
- <!-- 是否自动删除 -->
- <constructor-arg name="autoDelete" value="false"></constructor-arg>
- <!-- 是否持久化 -->
- <constructor-arg name="durable" value="true"></constructor-arg>
- <!-- 是否只能被声明者使用 -->
- <constructor-arg name="exclusive" value="false"></constructor-arg>
- <!-- 是都自动生成此对象 -->
- <property name="shouldDeclare" value="true"></property>
- </bean>
-
- <!-- 配置交换机 -->
- <bean id="directExchange" name="spring-test-exchange" class="org.springframework.amqp.core.DirectExchange">
- <!-- 交换机名称 -->
- <constructor-arg name="name" value="spring-test-exchange"></constructor-arg>
- <!-- 是否自动删除 -->
- <constructor-arg name="autoDelete" value="true"></constructor-arg>
- <!-- 是否持久化 -->
- <constructor-arg name="durable" value="true"></constructor-arg>
- </bean>
-
- <!-- 参数map 这个需要声明 绑定交换机的时候 必须输入这个参数 因为 它存在于构造函数中 会自动的解析 -->
- <bean id="arguments" class="java.util.HashMap"/>
- <!-- 绑定队列和交换机 -->
- <bean id="binding" class="org.springframework.amqp.core.Binding">
- <!-- 目的地 队列名 -->
- <constructor-arg name="destination" value="spring-test-queue"></constructor-arg>
- <!-- 目的类型 -->
- <constructor-arg name="destinationType" value="QUEUE"></constructor-arg>
- <!-- 交换机名称 -->
- <constructor-arg name="exchange" value="spring-test-exchange"></constructor-arg>
- <!-- 关键字 -->
- <constructor-arg name="routingKey" value="*-test-*"></constructor-arg>
- <!-- 自定义参数 -->
- <constructor-arg name="arguments" ref="arguments"></constructor-arg>
- </bean>
- <!-- 定义消息模板 -->
- <bean id="rabbitTemplate" class="org.springframework.amqp.rabbit.core.RabbitTemplate">
- <!-- 连接工厂 -->
- <property name="connectionFactory" ref="connectionFactory"></property>
- <!-- 交换机名称 -->
- <property name="exchange" value="spring-test-exchange"></property>
- </bean>
- <!-- 配置需要监听的类 -->
- <bean id="messageConsumer" class="com.julong.spring.consumer.MessageConsumer">
- </bean>
- <!-- 定义监听对象 -->
- <bean id="messageListenerAdapter" class="org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter">
- <property name="delegate" ref="messageConsumer"></property>
- <property name="defaultListenerMethod" value="onMessage"></property>
- <!-- <property name="responseExchange" value="spring-test-exchange"></property> -->
- </bean>
- <!-- 定义监听容器 -->
- <bean class="org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer">
- <property name="connectionFactory" ref="connectionFactory"></property>
- <property name="messageListener" ref="messageListenerAdapter"></property>
- <property name="queues" ref="springTestQueue"></property>
- <property name="rabbitAdmin" ref="rabbitAdmin"></property>
- </bean>
-
- </beans>
- <?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"
- xmlns:util="http://www.springframework.org/schema/util"
- xsi:schemaLocation="http://www.springframework.org/schema/rabbit
- http://www.springframework.org/schema/rabbit/spring-rabbit.xsd
- http://www.springframework.org/schema/util
- http://www.springframework.org/schema/util/spring-util.xsd
- http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">
- <description>rabbitmq版配置</description>
-
- <!-- 连接方式二 配置连接
- id : 编号
- host: 连接地址
- port: 端口
- username: 连接名称
- password: 密码
- virtual-host: 虚拟主机
- connection-limit:最大连接数
- cache-mode 缓存类型
- -->
- <rabbit:connection-factory id="connectionFactory"
- host="192.168.10.222" port="5672"
- username="julong" password="julong"
- virtual-host="/"
- connection-limit="25" cache-mode="CHANNEL" />
-
-
- <!-- 通过指定下面的admin信息,当前producer中的exchange和queue会在rabbitmq服务器上自动生成
- id: 编号
- connection-factory: 连接工厂
- auto-startup:是否自动启动
- -->
- <rabbit:admin id="rabbitAdmin" connection-factory="connectionFactory" auto-startup="true" />
-
- <!-- 创建队列
- id: 编号
- name:队列名称
- auto-delete:是否自动删除
- durable:是否持久化
- -->
- <rabbit:queue id="springTestQueue" name="spring-test-queue" auto-delete="false" durable="true" declared-by="rabbitAdmin" />
-
- <!-- 绑定交换机
- id: 交换机名称
- name:交换机名称
- -->
- <rabbit:direct-exchange id="directExchange" name="spring-test-exchange" auto-delete="true" declared-by="rabbitAdmin">
- <rabbit:bindings>
- <!-- 绑定交换机
- queue:队列名称
- key:路由键
- -->
- <rabbit:binding queue="spring-test-queue" key="" />
- </rabbit:bindings>
- </rabbit:direct-exchange>
-
- <!-- 定义消息接收发送模板类
- id:编号标识
- connection-factory:连接工厂
- exchange:交换机
- -->
- <rabbit:template id="rabbitmqTemplate" connection-factory="connectionFactory" exchange="spring-test-exchange" />
-
-
-
-
- </beans>
- package com.julong.spring.consumer;
-
- /**
- * 客户端消息接收类
- * @author julong
- * @date 2022年1月23日 下午2:44:11
- * @desc
- */
- public class MessageConsumer{
-
- public void onMessage(String message) {
- // TODO Auto-generated method stub
- System.out.println("客户端发送的消息是:"+message);
- }
-
-
- }
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">
- <!-- 引入配置文件 -->
- <!-- spring版配置 -->
- <import resource="applicationContext-rabbitmq-spring.xml" />
- <!-- rabbit版配置 -->
- <!-- <import resource="applicationContext-rabbitmq.xml" /> -->
- </beans>
启动类:
- package com.julong;
-
- import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
- import org.springframework.amqp.rabbit.core.RabbitAdmin;
- import org.springframework.amqp.rabbit.core.RabbitTemplate;
- import org.springframework.context.ApplicationContext;
- import org.springframework.context.support.FileSystemXmlApplicationContext;
-
- /**
- * spring 启动类
- * @author julong
- * @date 2022年1月20日 上午10:37:20
- * @desc
- */
- public class SpringApplicationStartMain {
- public static void main( String[] args ) {
-
- ApplicationContext context = new FileSystemXmlApplicationContext("classpath:applicationContext.xml");
- CachingConnectionFactory factory = (CachingConnectionFactory) context.getBean("connectionFactory");
- System.out.println("rabbitmq连接信息"+factory.toString());
- RabbitAdmin rabbitAdmin = (RabbitAdmin) context.getBean("rabbitAdmin");
- System.out.println("rabbitAdmin管理信息"+rabbitAdmin);
- RabbitTemplate rabbitTemplate = (RabbitTemplate) context.getBean("rabbitTemplate");
- System.out.println("rabbitTemplate模板信息"+rabbitTemplate);
- for (int i = 0; i < 10; i++) {
- rabbitTemplate.convertAndSend("spring-test-queue","spring to hello rabbitmq!"+System.currentTimeMillis());
- System.out.println("消息发送成功");
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- // Message message = rabbitTemplate.receive("spring-test-queue");
- // try {
- // if(null != message){
- // System.out.println("接收到发送的消息是:"+new String(message.getBody(), "utf-8"));
- // }
- // } catch (UnsupportedEncodingException e) {
- // // TODO Auto-generated catch block
- // e.printStackTrace();
- // }
- }
- }
服务端:
- 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]
- 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]
- 14:54:17.124 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] DEBUG o.s.retry.support.RetryTemplate - Retry: count=0
- 14:54:17.124 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] DEBUG o.s.amqp.rabbit.core.RabbitAdmin - Initializing declarations
- 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'
- 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'
- 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'
- 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.
- 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)
- 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]
- 14:54:17.174 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] DEBUG o.s.amqp.rabbit.core.RabbitAdmin - declaring Exchange 'spring-test-exchange'
- 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, {}])
- 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: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])
- 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-*]
- 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-*, {}])
- 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()
- 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)
- 14:54:17.184 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] DEBUG o.s.amqp.rabbit.core.RabbitAdmin - Declarations finished
- 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
- 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()
- 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]
- 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]
- 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])
- 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()
- 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)
- 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
- 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
- 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()
- 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]
- 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()
- 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])
- 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])
- 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'}])
- 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
- 14:54:17.214 [main] DEBUG o.s.c.s.DefaultLifecycleProcessor - Successfully started bean 'org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0'
- 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]
- 14:54:17.214 [main] TRACE o.s.c.e.PropertySourcesPropertyResolver - Searching for key 'spring.liveBeansView.mbeanDomain' in PropertySource 'systemProperties'
- 14:54:17.214 [main] TRACE o.s.c.e.PropertySourcesPropertyResolver - Searching for key 'spring.liveBeansView.mbeanDomain' in PropertySource 'systemEnvironment'
- 14:54:17.214 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Could not find key 'spring.liveBeansView.mbeanDomain' in any property source
- 14:54:17.214 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'connectionFactory'
- rabbitmq连接信息CachingConnectionFactory [channelCacheSize=25, host=192.168.10.222, port=5672, active=true connectionFactory]
- 14:54:17.214 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'rabbitAdmin'
- rabbitAdmin管理信息org.springframework.amqp.rabbit.core.RabbitAdmin@2145b572
- 14:54:17.214 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'rabbitTemplate'
- rabbitTemplate模板信息org.springframework.amqp.rabbit.core.RabbitTemplate@39529185
- 14:54:17.224 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] TRACE o.s.a.r.l.SimpleMessageListenerContainer - Waiting for message from consumer.
- 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
- 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
- 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]
- 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)
- 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]
- 14:54:17.234 [main] DEBUG o.s.amqp.rabbit.core.RabbitTemplate - Publishing message on exchange [spring-test-exchange], routingKey = [spring-test-queue]
- 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])
- 14:54:17.234 [main] TRACE o.s.a.r.c.CachingConnectionFactory - AMQChannel(amqp://julong@192.168.10.222:5672/,2) channel.close()
- 14:54:17.234 [main] TRACE o.s.a.r.c.CachingConnectionFactory - Returning cached Channel: AMQChannel(amqp://julong@192.168.10.222:5672/,2)
- 消息发送成功
- 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
- 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])
- 客户端发送的消息是:spring to hello rabbitmq!1642920857214
- 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
- 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])
- 14:54:17.244 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] TRACE o.s.a.r.l.SimpleMessageListenerContainer - Waiting for message from consumer.
- 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
- 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
- 14:54:18.234 [main] TRACE o.s.a.r.c.CachingConnectionFactory - AMQChannel(amqp://julong@192.168.10.222:5672/,2) channel.isOpen()
- 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]
- 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]
- 14:54:18.234 [main] DEBUG o.s.amqp.rabbit.core.RabbitTemplate - Publishing message on exchange [spring-test-exchange], routingKey = [spring-test-queue]
- 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])
- 14:54:18.234 [main] TRACE o.s.a.r.c.CachingConnectionFactory - AMQChannel(amqp://julong@192.168.10.222:5672/,2) channel.close()
- 14:54:18.234 [main] TRACE o.s.a.r.c.CachingConnectionFactory - Returning cached Channel: AMQChannel(amqp://julong@192.168.10.222:5672/,2)
- 消息发送成功
- 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
- 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])
- 客户端发送的消息是:spring to hello rabbitmq!1642920858234
- 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
- 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])
- 14:54:18.234 [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0-1] TRACE o.s.a.r.l.SimpleMessageListenerContainer - Waiting for message from consumer.
- 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
此处只做了一个简单的示例 客户端和服务端在一个工程中
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。