@Bean @ConditionalOnMissingBean(ConnectionNameStrategy.class) @ConditionalOnProperty("spring.cloud.stream.rabbit.binder.connection-name-prefix") public ConnectionNameStrategy connectionNamer(CachingConnectionFactory cf) { final AtomicInteger nameIncrementer = new AtomicInteger(); ConnectionNameStrategy namer = f -> this.rabbitBinderConfigurationProperties.getConnectionNamePrefix() + "#" + nameIncrementer.getAndIncrement(); // TODO: this can be removed when Boot 2.0.1 wires it in cf.setConnectionNameStrategy(namer); return namer; }
@Bean @ConditionalOnMissingBean(ConnectionNameStrategy.class) @ConditionalOnProperty("spring.cloud.stream.rabbit.binder.connection-name-prefix") public ConnectionNameStrategy connectionNamer(CachingConnectionFactory cf) { final AtomicInteger nameIncrementer = new AtomicInteger(); ConnectionNameStrategy namer = f -> this.rabbitBinderConfigurationProperties.getConnectionNamePrefix() + "#" + nameIncrementer.getAndIncrement(); // TODO: this can be removed when Boot 2.0.1 wires it in cf.setConnectionNameStrategy(namer); return namer; }
@Override public CachingConnectionFactory rabbitConnectionFactory(RabbitProperties config, ObjectProvider<ConnectionNameStrategy> connectionNameStrategy) throws Exception { CachingConnectionFactory cf = super.rabbitConnectionFactory(config, connectionNameStrategy); cf.setConnectionNameStrategy(new ConnectionNameStrategy() { @Override public String obtainNewConnectionName(ConnectionFactory connectionFactory) { return "rabbit.source.own.connection"; } }); cf.afterPropertiesSet(); return cf; }
@Override public CachingConnectionFactory rabbitConnectionFactory(RabbitProperties config, ObjectProvider<ConnectionNameStrategy> connectionNameStrategy) throws Exception { CachingConnectionFactory cf = super.rabbitConnectionFactory(config, connectionNameStrategy); cf.setConnectionNameStrategy(new ConnectionNameStrategy() { @Override public String obtainNewConnectionName(ConnectionFactory connectionFactory) { return "rabbit.sink.own.connection"; } }); cf.afterPropertiesSet(); return cf; }
@Before public void open() { connectionFactory = new CachingConnectionFactory("localhost"); connectionFactory.setPort(BrokerTestUtils.getPort()); connectionFactory.getRabbitConnectionFactory().getClientProperties().put("foo", "bar"); connectionFactory.setConnectionNameStrategy(cf -> CF_INTEGRATION_CONNECTION_NAME); }
@Test public void testConnectionCache() throws Exception { this.connectionCf.setConnectionNameStrategy(cf -> "testConnectionCache" + this.connNumber.getAndIncrement()); Connection c1 = this.connectionCf.createConnection(); Connection c2 = this.connectionCf.createConnection();
@Bean public ConnectionFactory rabbitConnectionFactory() { CachingConnectionFactory connectionFactory = new CachingConnectionFactory(); connectionFactory.setHost(brokerRunning.getHostName()); connectionFactory.setPort(brokerRunning.getPort()); connectionFactory.setUsername(brokerRunning.getUser()); connectionFactory.setPassword(brokerRunning.getPassword()); ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setThreadNamePrefix("rabbitClientThread-"); executor.afterPropertiesSet(); connectionFactory.setExecutor(executor); connectionFactory.setConnectionNameStrategy(cns()); return connectionFactory; }
@Test public void testChannelCache() throws Exception { this.channelCf.setConnectionNameStrategy(cf -> "testChannelCache"); Connection c1 = this.channelCf.createConnection(); Connection c2 = this.channelCf.createConnection();