List of usage examples for org.springframework.amqp.rabbit.listener DirectReplyToMessageListenerContainer DirectReplyToMessageListenerContainer
public DirectReplyToMessageListenerContainer(ConnectionFactory connectionFactory)
From source file:org.springframework.amqp.rabbit.AsyncRabbitTemplate.java
/** * Construct an instance using the provided arguments. "Direct replyTo" is used for * replies.//from w w w . j ava 2 s . c om * @param connectionFactory the connection factory. * @param exchange the default exchange to which requests will be sent. * @param routingKey the default routing key. * @since 2.0 */ public AsyncRabbitTemplate(ConnectionFactory connectionFactory, String exchange, String routingKey) { Assert.notNull(connectionFactory, "'connectionFactory' cannot be null"); Assert.notNull(routingKey, "'routingKey' cannot be null"); this.template = new RabbitTemplate(connectionFactory); this.template.setExchange(exchange == null ? "" : exchange); this.template.setRoutingKey(routingKey); this.container = null; this.replyAddress = null; this.directReplyToContainer = new DirectReplyToMessageListenerContainer( this.template.getConnectionFactory()); this.directReplyToContainer.setChannelAwareMessageListener(this); }
From source file:org.springframework.amqp.rabbit.AsyncRabbitTemplate.java
/** * Construct an instance using the provided arguments. "Direct replyTo" is used for * replies.//from w w w. j a va2 s. com * @param template a {@link RabbitTemplate} * @since 2.0 */ public AsyncRabbitTemplate(RabbitTemplate template) { Assert.notNull(template, "'template' cannot be null"); this.template = template; this.container = null; this.replyAddress = null; this.directReplyToContainer = new DirectReplyToMessageListenerContainer( this.template.getConnectionFactory()); this.directReplyToContainer.setChannelAwareMessageListener(this); }
From source file:org.springframework.amqp.rabbit.listener.DirectMessageListenerContainerIntegrationTests.java
@Test public void testReplyToReleaseWithCancel() throws Exception { CachingConnectionFactory cf = new CachingConnectionFactory("localhost"); DirectReplyToMessageListenerContainer container = new DirectReplyToMessageListenerContainer(cf); container.setBeanName("releaseCancel"); container.afterPropertiesSet();//from w ww . ja v a2s . c o m container.start(); ChannelHolder channelHolder = container.getChannelHolder(); final CountDownLatch latch = new CountDownLatch(1); container.setApplicationEventPublisher(e -> { if (e instanceof ListenerContainerConsumerTerminatedEvent) { latch.countDown(); } }); container.releaseConsumerFor(channelHolder, true, "foo"); assertTrue(latch.await(10, TimeUnit.SECONDS)); container.stop(); cf.destroy(); }
From source file:org.springframework.amqp.rabbit.listener.DirectMessageListenerContainerIntegrationTests.java
@Test public void testReplyToConsumersReduced() throws Exception { CachingConnectionFactory cf = new CachingConnectionFactory("localhost"); DirectReplyToMessageListenerContainer container = new DirectReplyToMessageListenerContainer(cf); container.setBeanName("reducing"); container.setIdleEventInterval(500); container.afterPropertiesSet();/*from ww w .j a v a 2s .c o m*/ container.start(); ChannelHolder channelHolder = container.getChannelHolder(); assertTrue(activeConsumerCount(container, 1)); container.releaseConsumerFor(channelHolder, false, null); assertTrue(activeConsumerCount(container, 0)); container.stop(); cf.destroy(); }
From source file:org.springframework.amqp.rabbit.listener.DirectMessageListenerContainerTests.java
@Test public void testReplyToReleaseWithCancel() throws Exception { CachingConnectionFactory cf = new CachingConnectionFactory("localhost"); DirectReplyToMessageListenerContainer container = new DirectReplyToMessageListenerContainer(cf); container.setBeanName("releaseCancel"); container.afterPropertiesSet();// ww w .j a va2 s . com container.start(); ChannelHolder channelHolder = container.getChannelHolder(); final CountDownLatch latch = new CountDownLatch(1); container.setApplicationEventPublisher(e -> { if (e instanceof ListenerContainerConsumerTerminatedEvent) { latch.countDown(); } }); container.releaseConsumerFor(channelHolder, true, "foo"); assertTrue(latch.await(10, TimeUnit.SECONDS)); }
From source file:org.springframework.amqp.rabbit.listener.DirectMessageListenerContainerTests.java
@Test public void testReplyToConsumersReduced() throws Exception { CachingConnectionFactory cf = new CachingConnectionFactory("localhost"); DirectReplyToMessageListenerContainer container = new DirectReplyToMessageListenerContainer(cf); container.setBeanName("reducing"); container.setIdleEventInterval(500); container.afterPropertiesSet();/*from ww w .j a va2s.co m*/ container.start(); ChannelHolder channelHolder = container.getChannelHolder(); assertTrue(activeConsumerCount(container, 1)); container.releaseConsumerFor(channelHolder, false, null); assertTrue(activeConsumerCount(container, 0)); }