use of org.springframework.amqp.rabbit.listener.BlockingQueueConsumer in project spring-integration by spring-projects.
the class ChannelTests method pubSubLostConnectionTest.
@Test
public void pubSubLostConnectionTest() throws Exception {
final CyclicBarrier latch = new CyclicBarrier(2);
channel.subscribe(message -> {
try {
latch.await(10, TimeUnit.SECONDS);
} catch (Exception e) {
}
});
this.channel.send(new GenericMessage<>("foo"));
latch.await(10, TimeUnit.SECONDS);
latch.reset();
BlockingQueueConsumer consumer = (BlockingQueueConsumer) TestUtils.getPropertyValue(this.channel, "container.consumers", Set.class).iterator().next();
connectionFactory.destroy();
waitForNewConsumer(this.channel, consumer);
this.channel.send(new GenericMessage<>("bar"));
latch.await(10, TimeUnit.SECONDS);
this.channel.destroy();
this.pubSubWithEP.destroy();
this.withEP.destroy();
this.pollableWithEP.destroy();
assertThat(TestUtils.getPropertyValue(connectionFactory, "connectionListener.delegates", Collection.class).size()).isEqualTo(0);
}
use of org.springframework.amqp.rabbit.listener.BlockingQueueConsumer in project spring-amqp by spring-projects.
the class RabbitBindingIntegrationTests method testSendAndReceiveWithTopicTwoCallbacks.
@Test
public void testSendAndReceiveWithTopicTwoCallbacks() {
RabbitAdmin admin = new RabbitAdmin(connectionFactory);
TopicExchange exchange = new TopicExchange("topic");
admin.declareExchange(exchange);
template.setExchange(exchange.getName());
admin.declareBinding(BindingBuilder.bind(QUEUE).to(exchange).with("*.end"));
template.execute(channel -> {
BlockingQueueConsumer consumer = createConsumer(template);
String tag = consumer.getConsumerTags().iterator().next();
assertThat(tag).isNotNull();
try {
template.convertAndSend("foo", "message");
String result = getResult(consumer, false);
assertThat(result).isEqualTo(null);
} finally {
consumer.stop();
}
return null;
});
template.execute(channel -> {
BlockingQueueConsumer consumer = createConsumer(template);
String tag = consumer.getConsumerTags().iterator().next();
assertThat(tag).isNotNull();
try {
template.convertAndSend("foo.end", "message");
String result = getResult(consumer, true);
assertThat(result).isEqualTo("message");
} finally {
consumer.stop();
}
return null;
});
admin.deleteExchange("topic");
}
use of org.springframework.amqp.rabbit.listener.BlockingQueueConsumer in project spring-amqp by spring-projects.
the class RabbitBindingIntegrationTests method testSendAndReceiveWithFanout.
@Test
public void testSendAndReceiveWithFanout() {
RabbitAdmin admin = new RabbitAdmin(connectionFactory);
FanoutExchange exchange = new FanoutExchange("fanout");
admin.declareExchange(exchange);
template.setExchange(exchange.getName());
admin.declareBinding(BindingBuilder.bind(QUEUE).to(exchange));
template.execute(channel -> {
BlockingQueueConsumer consumer = createConsumer(template);
String tag = consumer.getConsumerTags().iterator().next();
assertThat(tag).isNotNull();
try {
template.convertAndSend("message");
String result = getResult(consumer, true);
assertThat(result).isEqualTo("message");
} finally {
consumer.stop();
}
return null;
});
admin.deleteExchange("fanout");
}
use of org.springframework.amqp.rabbit.listener.BlockingQueueConsumer in project spring-amqp by spring-projects.
the class RabbitBindingIntegrationTests method testSendAndReceiveWithTopicConsumeInBackground.
@Test
public // @Ignore("Not sure yet if we need to support a use case like this")
void testSendAndReceiveWithTopicConsumeInBackground() throws Exception {
RabbitAdmin admin = new RabbitAdmin(connectionFactory);
TopicExchange exchange = new TopicExchange("topic");
admin.declareExchange(exchange);
template.setExchange(exchange.getName());
admin.declareBinding(BindingBuilder.bind(QUEUE).to(exchange).with("*.end"));
final CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();
cachingConnectionFactory.setHost("localhost");
final RabbitTemplate template1 = new RabbitTemplate(cachingConnectionFactory);
template1.setExchange(exchange.getName());
BlockingQueueConsumer consumer = template1.execute(channel -> {
BlockingQueueConsumer consumer1 = createConsumer(template1);
String tag = consumer1.getConsumerTags().iterator().next();
assertThat(tag).isNotNull();
return consumer1;
});
template1.convertAndSend("foo", "message");
String result = getResult(consumer, false);
assertThat(result).isEqualTo(null);
template1.convertAndSend("foo.end", "message");
result = getResult(consumer, true);
assertThat(result).isEqualTo("message");
consumer.stop();
admin.deleteExchange("topic");
cachingConnectionFactory.destroy();
}
use of org.springframework.amqp.rabbit.listener.BlockingQueueConsumer in project spring-integration by spring-projects.
the class ChannelTests method waitForNewConsumer.
@SuppressWarnings("unchecked")
private void waitForNewConsumer(PublishSubscribeAmqpChannel channel, BlockingQueueConsumer consumer) throws Exception {
final Object consumersMonitor = TestUtils.getPropertyValue(channel, "container.consumersMonitor");
int n = 0;
while (n++ < 100) {
Set<BlockingQueueConsumer> consumers = TestUtils.getPropertyValue(channel, "container.consumers", Set.class);
synchronized (consumersMonitor) {
if (!consumers.isEmpty()) {
BlockingQueueConsumer newConsumer = consumers.iterator().next();
if (newConsumer != consumer && newConsumer.getConsumerTags().size() > 0) {
break;
}
}
}
Thread.sleep(100);
}
assertThat(n < 100).as("Failed to restart consumer").isTrue();
}
Aggregations