通常我们使用RabbitTemplate来进行简单的收发消息,而RabbitTemplate使用CachingConnectionFactory作为连接工厂, CachingConnectionFactory...配置bean @Bean public CachingConnectionFactory cachingConnectionFactory(){ CachingConnectionFactory...private CachingConnectionFactory getCachingConnectionFactory() { CachingConnectionFactory cachingConnectionFactory...= new CachingConnectionFactory(); cachingConnectionFactory.setAddresses(rabbitProperties.getAddresses...); cachingConnectionFactory.setRecoveryListener(rabbitRecoveryListener); return cachingConnectionFactory
connectionFactory() { CachingConnectionFactory connectionFactory = new CachingConnectionFactory...三、错误代码示例 以下是一个可能导致该报错的代码示例,并解释其错误之处: import org.springframework.amqp.rabbit.connection.CachingConnectionFactory...connectionFactory() { CachingConnectionFactory connectionFactory = new CachingConnectionFactory...connectionFactory() { CachingConnectionFactory connectionFactory = new CachingConnectionFactory...(5000); return connectionFactory; } @Bean public RabbitTemplate rabbitTemplate(CachingConnectionFactory
(CachingConnectionFactory.java:614) ~[spring-rabbit-2.0.3.RELEASE.jar!...(CachingConnectionFactory.java:564) ~[spring-rabbit-2.0.3.RELEASE.jar!...(CachingConnectionFactory.java:538) ~[spring-rabbit-2.0.3.RELEASE.jar!...(CachingConnectionFactory.java:520) ~[spring-rabbit-2.0.3.RELEASE.jar!...(CachingConnectionFactory.java:614) ~[spring-rabbit-2.0.3.RELEASE.jar!
ConnectionFactory和RabbitTemplate package com.xsh.mq.config; import org.springframework.amqp.rabbit.connection.CachingConnectionFactory...private String password; @Bean public ConnectionFactory connectionFactory() { CachingConnectionFactory...cachingConnectionFactory = new CachingConnectionFactory(host,port); cachingConnectionFactory.setUsername...(userName); cachingConnectionFactory.setPassword(password); cachingConnectionFactory.setVirtualHost...("/"); cachingConnectionFactory.setPublisherConfirms(true); return cachingConnectionFactory
public class RabbitMQConfig { @Bean public ConnectionFactory connectionFactory() { CachingConnectionFactory...factory = new CachingConnectionFactory("localhost"); factory.setUsername("guest"); factory.setPassword...public class RabbitMQConfig { @Bean public ConnectionFactory connectionFactory() { CachingConnectionFactory...factory = new CachingConnectionFactory("localhost"); // 错误的用户名或密码 factory.setUsername...factory = new CachingConnectionFactory("localhost"); // 正确的用户名和密码 factory.setUsername
RabbitTemplate 也很简单,代码如下: package com.mq.rabbitmq; import org.springframework.amqp.rabbit.connection.CachingConnectionFactory...private String password; @Bean public ConnectionFactory connectionFactory() { CachingConnectionFactory...cachingConnectionFactory = new CachingConnectionFactory(host,port); cachingConnectionFactory.setUsername...(userName); cachingConnectionFactory.setPassword(password); cachingConnectionFactory.setVirtualHost...("/"); cachingConnectionFactory.setPublisherConfirms(true); return cachingConnectionFactory
三、错误代码示例 以下是一个可能导致该报错的代码示例,并解释其错误之处: import org.springframework.amqp.rabbit.connection.CachingConnectionFactory...org.springframework.context.annotation.Configuration; @Configuration public class RabbitConfig { @Bean public CachingConnectionFactory...connectionFactory() { CachingConnectionFactory connectionFactory = new CachingConnectionFactory...以下是正确的代码示例: import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; import org.springframework.context.annotation.Bean...connectionFactory() { CachingConnectionFactory connectionFactory = new CachingConnectionFactory
ConnectionFactory Spring提供了两个javax.jms.ConnectionFactory的实现:SingleConnectionFactory和CachingConnectionFactory...CachingConnectionFactory CachingConnectionFactory继承自SingleConnectionFactory,除了依然保留缓存同一个Connection实例的特性外...CachingConnectionFactory其内部维护了一个Acknowledge Mode -> List的Map,sessionCacheSize实际上指的是List<Session...并且CachingConnectionFactory其本质不是一个Object Pool,所以不会因为实际请求Session数量超出sessionCacheSize导致block或者返回null,可以放心使用...可以通过CachingConnectionFactory了解详情。
配置bean @Bean public RabbitAdmin rabbitAdmin(CachingConnectionFactory cachingConnectionFactory){...RabbitAdmin rabbitAdmin = new RabbitAdmin(cachingConnectionFactory); rabbitAdmin.setIgnoreDeclarationExceptions
spring-rabbit-2.1.2.RELEASE.jar:2.1.2.RELEASE] 4 at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection...(CachingConnectionFactory.java:684) ~[spring-rabbit-2.1.2.RELEASE.jar:2.1.2.RELEASE] 5 at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.createConnection...9 common frames omitted 28 29 2019-11-21 22:54:45.267 INFO 19532 --- [TaskExecutor-25] o.s.a.r.c.CachingConnectionFactory...acknowledgeMode=AUTO local queue size=0 32 2019-11-21 22:54:49.262 INFO 19532 --- [TaskExecutor-25] o.s.a.r.c.CachingConnectionFactory
Configuration public class RabbitConfig { @Bean public ConnectionFactory connectionFactory() { CachingConnectionFactory...factory = new CachingConnectionFactory(); factory.setHost("localhost"); factory.setPort...Configuration public class RabbitConfig { @Bean public ConnectionFactory connectionFactory() { CachingConnectionFactory...factory = new CachingConnectionFactory(); factory.setHost("localhost"); factory.setPort
factory=new CachingConnectionFactory(); 21 System.out.println(host); 22 factory.setHost(host); 23 factory.setPort...factory=new CachingConnectionFactory(); 21 factory.setHost(host); 22 factory.setPort(port); 23 factory.setUsername...factory=new CachingConnectionFactory(); 21 System.out.println(host); 22 factory.setHost(host); 23...factory=new CachingConnectionFactory(); 21 factory.setHost(host); 22 factory.setPort(port); 23 factory.setUsername...factory=new CachingConnectionFactory(); 21 System.out.println(host); 22 factory.setHost(host); 23
private Environment environment; @Bean public ConnectionFactory connectionFactory() { CachingConnectionFactory...factory = new CachingConnectionFactory(); factory.setHost(environment.getProperty("dyn.mq.host...private Environment environment; @Bean public ConnectionFactory connectionFactory() { CachingConnectionFactory...factory = new CachingConnectionFactory(); factory.setHost(environment.getProperty("dyn.mq.host...factory = new CachingConnectionFactory(); factory.setHost(environment.getProperty("dyn.mq.host
org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory; import org.springframework.amqp.rabbit.connection.CachingConnectionFactory...public class ConsumerConfig { @Bean public ConnectionFactory connectionFactory(){ CachingConnectionFactory...factory = new CachingConnectionFactory(); factory.setUri("amqp://zhihao.miao:123456@192.168.1.131
org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory; import org.springframework.amqp.rabbit.connection.CachingConnectionFactory...spring.rabbitmq.first.password}") String password, @Value("${spring.rabbitmq.first.virtual-host}") String virtualHost ) { CachingConnectionFactory...connectionFactory = new CachingConnectionFactory(); connectionFactory.setAddresses(addresses); connectionFactory.setUsername...spring.rabbitmq.second.password}") String password, @Value("${spring.rabbitmq.second.virtual-host}") String virtualHost ) { CachingConnectionFactory...connectionFactory = new CachingConnectionFactory(); connectionFactory.setHost(host); connectionFactory.setPort
下面看基于缓存的 CachingConnectionFactory 的创建源码。...Cache cacheProperties = jmsProperties . getCache(); CachingConnectionFactory connectionFactory = new...创建 CachingConnectionFactory 的过程就是 new 一个 CachingConnectionFactory对象,其参数包含上面我们讲到的 ActiveMQConnectionFactory...CachingConnectionFactory 是 SingleConnectionFactory 的子类,它添加了会话( Session)缓 存 以 及 MessageProducer 缓 存 。...CachingConnectionFactory 默认情况下,只会缓存一个会话,其他进一步的回话请求会按照需要创建并处理。在高并发环境下,要考虑提高“sessionCacheSize'的值。
hello, aaa, bbb就是容器从RabbitMQ收到的消息: 2018-05-12 10:40:23.851 INFO 1 --- [cTaskExecutor-2] o.s.a.r.c.CachingConnectionFactory...to connect to: [rabbitmqhost:5672] 2018-05-12 10:40:28.900 INFO 1 --- [cTaskExecutor-3] o.s.a.r.c.CachingConnectionFactory...hello, aaa, bbb就是容器从RabbitMQ收到的消息: 2018-05-12 11:59:17.112 INFO 1 --- [cTaskExecutor-4] o.s.a.r.c.CachingConnectionFactory...to connect to: [rabbitmqhost:5672] 2018-05-12 11:59:17.172 INFO 1 --- [cTaskExecutor-4] o.s.a.r.c.CachingConnectionFactory...to connect to: [rabbitmqhost:5672] 2018-05-12 11:59:12.263 INFO 1 --- [cTaskExecutor-3] o.s.a.r.c.CachingConnectionFactory
Configuration public class MultipleRabbitMQConfig { @Bean(name = "v2ConnectionFactory") public CachingConnectionFactory..., @Value("${v2.spring.rabbitmq.publisher-returns}") Boolean publisherReturns) { CachingConnectionFactory...connectionFactory = new CachingConnectionFactory(); connectionFactory.setHost(host);..., @Value("${v1.spring.rabbitmq.publisher-returns}") Boolean publisherReturns) { CachingConnectionFactory...connectionFactory = new CachingConnectionFactory(); connectionFactory.setHost(host);
CachingConnectionFactory factory = new CachingConnectionFactory(); factory.setPublisherConfirms(true)...CachingConnectionFactory factory = new CachingConnectionFactory(); factory.setPublisherReturns(true);
send message: 支付订单号:1526286535342 2018-05-14 16:28:55.383 INFO 10624 --- [ main] o.s.a.r.c.CachingConnectionFactory...connect to: [192.168.15.131:5672] 2018-05-14 16:28:55.444 INFO 10624 --- [ main] o.s.a.r.c.CachingConnectionFactory...2018-05-14 16:30:07.463 INFO 7340 --- [ main] o.s.a.r.c.CachingConnectionFactory : Attempting...2018-05-14 16:31:14.638 INFO 6460 --- [ main] o.s.a.r.c.CachingConnectionFactory : Attempting...2018-05-14 16:33:43.054 INFO 14356 --- [ main] o.s.a.r.c.CachingConnectionFactory :
领取专属 10元无门槛券
手把手带您无忧上云