public void setConnectionCacheSize(int connectionCacheSize) { Assert.isTrue(connectionCacheSize >= 1, "Connection cache size must be 1 or higher."); this.connectionCacheSize = connectionCacheSize; if (this.publisherConnectionFactory != null) { this.publisherConnectionFactory.setConnectionCacheSize(connectionCacheSize); } }
public void setConnectionCacheSize(int connectionCacheSize) { Assert.isTrue(connectionCacheSize >= 1, "Connection cache size must be 1 or higher."); this.connectionCacheSize = connectionCacheSize; if (this.publisherConnectionFactory != null) { this.publisherConnectionFactory.setConnectionCacheSize(connectionCacheSize); } }
@Bean public CachingConnectionFactory connectionCf() { CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory("localhost"); cachingConnectionFactory.setChannelCacheSize(10); cachingConnectionFactory.setConnectionCacheSize(5); cachingConnectionFactory.setCacheMode(CacheMode.CONNECTION); return cachingConnectionFactory; }
@Test public void testCachedConnectionsChannelLimit() throws Exception { connectionFactory.setCacheMode(CacheMode.CONNECTION); connectionFactory.setConnectionCacheSize(2); connectionFactory.setChannelCacheSize(1); connectionFactory.setChannelCheckoutTimeout(10);
@Test public void testCachedConnections() { connectionFactory.setCacheMode(CacheMode.CONNECTION); connectionFactory.setConnectionCacheSize(5); connectionFactory.setExecutor(Executors.newCachedThreadPool()); List<Connection> connections = new ArrayList<>(); connections.add(connectionFactory.createConnection()); connections.add(connectionFactory.createConnection()); assertNotSame(connections.get(0), connections.get(1)); connections.add(connectionFactory.createConnection()); connections.add(connectionFactory.createConnection()); connections.add(connectionFactory.createConnection()); connections.add(connectionFactory.createConnection()); Set<?> allocatedConnections = TestUtils.getPropertyValue(connectionFactory, "allocatedConnections", Set.class); assertEquals(6, allocatedConnections.size()); connections.forEach(Connection::close); assertEquals(6, allocatedConnections.size()); assertEquals("5", connectionFactory.getCacheProperties().get("openConnections")); BlockingQueue<?> idleConnections = TestUtils.getPropertyValue(connectionFactory, "idleConnections", BlockingQueue.class); assertEquals(6, idleConnections.size()); connections.clear(); connections.add(connectionFactory.createConnection()); connections.add(connectionFactory.createConnection()); assertEquals(6, allocatedConnections.size()); assertEquals(4, idleConnections.size()); connections.forEach(Connection::close); }
ccf.setExecutor(mock(ExecutorService.class)); ccf.setCacheMode(CacheMode.CONNECTION); ccf.setConnectionCacheSize(1); ccf.setConnectionLimit(1); ccf.setChannelCheckoutTimeout(10);
@Test public void testCachedConnectionsAndChannels() throws Exception { connectionFactory.setCacheMode(CacheMode.CONNECTION); connectionFactory.setConnectionCacheSize(1); connectionFactory.setChannelCacheSize(3);
ccf.setExecutor(mock(ExecutorService.class)); ccf.setCacheMode(CacheMode.CONNECTION); ccf.setConnectionCacheSize(5); ccf.afterPropertiesSet();
ccf.setExecutor(mock(ExecutorService.class)); ccf.setCacheMode(CacheMode.CONNECTION); ccf.setConnectionCacheSize(2); ccf.setChannelCacheSize(2); ccf.afterPropertiesSet();
static void configureCachingConnectionFactory(CachingConnectionFactory connectionFactory, ConfigurableApplicationContext applicationContext, RabbitProperties rabbitProperties) throws Exception { if (StringUtils.hasText(rabbitProperties.getAddresses())) { connectionFactory.setAddresses(rabbitProperties.determineAddresses()); } connectionFactory.setPublisherConfirms(rabbitProperties.isPublisherConfirms()); connectionFactory.setPublisherReturns(rabbitProperties.isPublisherReturns()); if (rabbitProperties.getCache().getChannel().getSize() != null) { connectionFactory.setChannelCacheSize(rabbitProperties.getCache().getChannel().getSize()); } if (rabbitProperties.getCache().getConnection().getMode() != null) { connectionFactory.setCacheMode(rabbitProperties.getCache().getConnection().getMode()); } if (rabbitProperties.getCache().getConnection().getSize() != null) { connectionFactory.setConnectionCacheSize( rabbitProperties.getCache().getConnection().getSize()); } if (rabbitProperties.getCache().getChannel().getCheckoutTimeout() != null) { connectionFactory.setChannelCheckoutTimeout( rabbitProperties.getCache().getChannel().getCheckoutTimeout().toMillis()); } connectionFactory.setApplicationContext(applicationContext); applicationContext.addApplicationListener(connectionFactory); connectionFactory.afterPropertiesSet(); }
static void configureCachingConnectionFactory(CachingConnectionFactory connectionFactory, ConfigurableApplicationContext applicationContext, RabbitProperties rabbitProperties) throws Exception { if (StringUtils.hasText(rabbitProperties.getAddresses())) { connectionFactory.setAddresses(rabbitProperties.determineAddresses()); } connectionFactory.setPublisherConfirms(rabbitProperties.isPublisherConfirms()); connectionFactory.setPublisherReturns(rabbitProperties.isPublisherReturns()); if (rabbitProperties.getCache().getChannel().getSize() != null) { connectionFactory.setChannelCacheSize(rabbitProperties.getCache().getChannel().getSize()); } if (rabbitProperties.getCache().getConnection().getMode() != null) { connectionFactory.setCacheMode(rabbitProperties.getCache().getConnection().getMode()); } if (rabbitProperties.getCache().getConnection().getSize() != null) { connectionFactory.setConnectionCacheSize( rabbitProperties.getCache().getConnection().getSize()); } if (rabbitProperties.getCache().getChannel().getCheckoutTimeout() != null) { connectionFactory.setChannelCheckoutTimeout( rabbitProperties.getCache().getChannel().getCheckoutTimeout().toMillis()); } connectionFactory.setApplicationContext(applicationContext); applicationContext.addApplicationListener(connectionFactory); connectionFactory.afterPropertiesSet(); }