@Override public boolean cancel(boolean mayInterruptIfRunning) { if (this.timeoutTask != null) { this.timeoutTask.cancel(true); } AsyncRabbitTemplate.this.pending.remove(this.correlationId); if (this.channelHolder != null && AsyncRabbitTemplate.this.directReplyToContainer != null) { AsyncRabbitTemplate.this.directReplyToContainer.releaseConsumerFor(this.channelHolder, false, null); // NOSONAR } return super.cancel(mayInterruptIfRunning); }
@Override public boolean cancel(boolean mayInterruptIfRunning) { if (this.timeoutTask != null) { this.timeoutTask.cancel(true); } AsyncRabbitTemplate.this.pending.remove(this.correlationId); if (this.channelHolder != null && AsyncRabbitTemplate.this.directReplyToContainer != null) { AsyncRabbitTemplate.this.directReplyToContainer.releaseConsumerFor(this.channelHolder, false, null); // NOSONAR } return super.cancel(mayInterruptIfRunning); }
container.releaseConsumerFor(channelHolder, false, null);
container.releaseConsumerFor(channelHolder, false, null);
@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(); }
container.releaseConsumerFor(channel1, false, null); // simulate race for future timeout/cancel and onMessage() Map<?, ?> inUse = TestUtils.getPropertyValue(container, "inUseConsumerChannels", Map.class); assertThat(inUse.size(), equalTo(1)); container.releaseConsumerFor(channel2, false, null); assertThat(inUse.size(), equalTo(0)); container.stop();