container = new DirectReplyToMessageListenerContainer(connectionFactory); container.setMessageListener(this); container.setBeanName(this.beanName + "#" + this.containerInstance.getAndIncrement()); if (this.taskExecutor != null) { container.setTaskExecutor(this.taskExecutor);
container = new DirectReplyToMessageListenerContainer(connectionFactory); container.setMessageListener(this); container.setBeanName(this.beanName + "#" + this.containerInstance.getAndIncrement()); if (this.taskExecutor != null) { container.setTaskExecutor(this.taskExecutor);
@Test public void testReplyToReleaseWithCancel() throws Exception { CachingConnectionFactory cf = new CachingConnectionFactory("localhost"); DirectReplyToMessageListenerContainer container = new DirectReplyToMessageListenerContainer(cf); container.setBeanName("releaseCancel"); final CountDownLatch consumeLatch = new CountDownLatch(1); final CountDownLatch releaseLatch = new CountDownLatch(1); container.setApplicationEventPublisher(e -> { if (e instanceof ListenerContainerConsumerTerminatedEvent) { releaseLatch.countDown(); } else if (e instanceof ConsumeOkEvent) { consumeLatch.countDown(); } }); container.afterPropertiesSet(); container.start(); ChannelHolder channelHolder = container.getChannelHolder(); assertTrue(consumeLatch.await(10, TimeUnit.SECONDS)); container.releaseConsumerFor(channelHolder, true, "foo"); assertTrue(releaseLatch.await(10, TimeUnit.SECONDS)); container.stop(); cf.destroy(); }
@Test public void testReplyToConsumersReduced() throws Exception { CachingConnectionFactory cf = new CachingConnectionFactory("localhost"); DirectReplyToMessageListenerContainer container = new DirectReplyToMessageListenerContainer(cf); container.setBeanName("reducing"); container.setIdleEventInterval(100); CountDownLatch latch = new CountDownLatch(5); container.setApplicationEventPublisher(e -> { if (e instanceof ListenerContainerIdleEvent) { latch.countDown(); } }); container.afterPropertiesSet(); container.start(); ChannelHolder channelHolder1 = container.getChannelHolder(); ChannelHolder channelHolder2 = container.getChannelHolder(); assertTrue(activeConsumerCount(container, 2)); container.releaseConsumerFor(channelHolder2, false, null); assertTrue(latch.await(10, TimeUnit.SECONDS)); assertTrue(channelHolder1.getChannel().isOpen()); container.releaseConsumerFor(channelHolder1, false, null); assertTrue(activeConsumerCount(container, 0)); container.stop(); cf.destroy(); }