Java Code Examples for org.springframework.amqp.rabbit.core.RabbitTemplate#receiveAndConvert()
The following examples show how to use
org.springframework.amqp.rabbit.core.RabbitTemplate#receiveAndConvert() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RabbitBinderTests.java From spring-cloud-stream-binder-rabbit with Apache License 2.0 | 5 votes |
@Override public Spy spyOn(final String queue) { final RabbitTemplate template = new RabbitTemplate( this.rabbitAvailableRule.getResource()); template.setAfterReceivePostProcessors( new DelegatingDecompressingPostProcessor()); return new Spy() { @Override public Object receive(boolean expectNull) throws Exception { if (expectNull) { Thread.sleep(50); return template.receiveAndConvert( new RabbitConsumerProperties().getPrefix() + queue); } Object bar = null; int n = 0; while (n++ < 100 && bar == null) { bar = template.receiveAndConvert( new RabbitConsumerProperties().getPrefix() + queue); Thread.sleep(100); } assertThat(n).isLessThan(100) .withFailMessage("Message did not arrive in RabbitMQ"); return bar; } }; }
Example 2
Source File: RabbitBinderTests.java From spring-cloud-stream-binder-rabbit with Apache License 2.0 | 4 votes |
@Test public void testDurablePubSubWithAutoBindDLQ() throws Exception { RabbitAdmin admin = new RabbitAdmin(this.rabbitAvailableRule.getResource()); RabbitTestBinder binder = getBinder(); ExtendedConsumerProperties<RabbitConsumerProperties> consumerProperties = createConsumerProperties(); consumerProperties.getExtension().setPrefix(TEST_PREFIX); consumerProperties.getExtension().setAutoBindDlq(true); consumerProperties.getExtension().setDurableSubscription(true); consumerProperties.setMaxAttempts(1); // disable retry DirectChannel moduleInputChannel = createBindableChannel("input", createConsumerBindingProperties(consumerProperties)); moduleInputChannel.setBeanName("durableTest"); moduleInputChannel.subscribe(new MessageHandler() { @Override public void handleMessage(Message<?> message) throws MessagingException { throw new RuntimeException("foo"); } }); Binding<MessageChannel> consumerBinding = binder.bindConsumer("durabletest.0", "tgroup", moduleInputChannel, consumerProperties); RabbitTemplate template = new RabbitTemplate( this.rabbitAvailableRule.getResource()); template.convertAndSend(TEST_PREFIX + "durabletest.0", "", "foo"); int n = 0; while (n++ < 100) { Object deadLetter = template .receiveAndConvert(TEST_PREFIX + "durabletest.0.tgroup.dlq"); if (deadLetter != null) { assertThat(deadLetter).isEqualTo("foo"); break; } Thread.sleep(100); } assertThat(n).isLessThan(100); consumerBinding.unbind(); assertThat(admin.getQueueProperties(TEST_PREFIX + "durabletest.0.tgroup.dlq")) .isNotNull(); }