List of usage examples for org.springframework.amqp.rabbit.listener SimpleMessageListenerContainer getAcknowledgeMode
public AcknowledgeMode getAcknowledgeMode()
From source file:org.springframework.cloud.stream.binder.rabbit.RabbitBinderTests.java
@Test public void testConsumerProperties() throws Exception { RabbitTestBinder binder = getBinder(); ExtendedConsumerProperties<RabbitConsumerProperties> properties = createConsumerProperties(); properties.getExtension().setRequeueRejected(true); properties.getExtension().setTransacted(true); properties.getExtension().setExclusive(true); Binding<MessageChannel> consumerBinding = binder.bindConsumer("props.0", null, createBindableChannel("input", new BindingProperties()), properties); Lifecycle endpoint = extractEndpoint(consumerBinding); SimpleMessageListenerContainer container = TestUtils.getPropertyValue(endpoint, "messageListenerContainer", SimpleMessageListenerContainer.class); assertThat(container.getAcknowledgeMode()).isEqualTo(AcknowledgeMode.AUTO); assertThat(container.getQueueNames()[0]).startsWith(properties.getExtension().getPrefix()); assertThat(TestUtils.getPropertyValue(container, "transactional", Boolean.class)).isTrue(); assertThat(TestUtils.getPropertyValue(container, "exclusive", Boolean.class)).isTrue(); assertThat(TestUtils.getPropertyValue(container, "concurrentConsumers")).isEqualTo(1); assertThat(TestUtils.getPropertyValue(container, "maxConcurrentConsumers")).isNull(); assertThat(TestUtils.getPropertyValue(container, "defaultRequeueRejected", Boolean.class)).isTrue(); assertThat(TestUtils.getPropertyValue(container, "prefetchCount")).isEqualTo(1); assertThat(TestUtils.getPropertyValue(container, "txSize")).isEqualTo(1); RetryTemplate retry = TestUtils.getPropertyValue(endpoint, "retryTemplate", RetryTemplate.class); assertThat(TestUtils.getPropertyValue(retry, "retryPolicy.maxAttempts")).isEqualTo(3); assertThat(TestUtils.getPropertyValue(retry, "backOffPolicy.initialInterval")).isEqualTo(1000L); assertThat(TestUtils.getPropertyValue(retry, "backOffPolicy.maxInterval")).isEqualTo(10000L); assertThat(TestUtils.getPropertyValue(retry, "backOffPolicy.multiplier")).isEqualTo(2.0); consumerBinding.unbind();/*www .java 2s . co m*/ assertThat(endpoint.isRunning()).isFalse(); properties = createConsumerProperties(); properties.getExtension().setAcknowledgeMode(AcknowledgeMode.NONE); properties.setBackOffInitialInterval(2000); properties.setBackOffMaxInterval(20000); properties.setBackOffMultiplier(5.0); properties.setConcurrency(2); properties.setMaxAttempts(23); properties.getExtension().setMaxConcurrency(3); properties.getExtension().setPrefix("foo."); properties.getExtension().setPrefetch(20); properties.getExtension().setHeaderPatterns(new String[] { "foo" }); properties.getExtension().setTxSize(10); properties.setInstanceIndex(0); consumerBinding = binder.bindConsumer("props.0", "test", createBindableChannel("input", new BindingProperties()), properties); endpoint = extractEndpoint(consumerBinding); container = verifyContainer(endpoint); assertThat(container.getQueueNames()[0]).isEqualTo("foo.props.0.test"); consumerBinding.unbind(); assertThat(endpoint.isRunning()).isFalse(); }
From source file:org.springframework.cloud.stream.binder.rabbit.RabbitBinderTests.java
private SimpleMessageListenerContainer verifyContainer(Lifecycle endpoint) { SimpleMessageListenerContainer container; RetryTemplate retry;//from w w w . j a v a 2s . c o m container = TestUtils.getPropertyValue(endpoint, "messageListenerContainer", SimpleMessageListenerContainer.class); assertThat(container.getAcknowledgeMode()).isEqualTo(AcknowledgeMode.NONE); assertThat(container.getQueueNames()[0]).startsWith("foo.props.0"); assertThat(TestUtils.getPropertyValue(container, "transactional", Boolean.class)).isFalse(); assertThat(TestUtils.getPropertyValue(container, "concurrentConsumers")).isEqualTo(2); assertThat(TestUtils.getPropertyValue(container, "maxConcurrentConsumers")).isEqualTo(3); assertThat(TestUtils.getPropertyValue(container, "defaultRequeueRejected", Boolean.class)).isFalse(); assertThat(TestUtils.getPropertyValue(container, "prefetchCount")).isEqualTo(20); assertThat(TestUtils.getPropertyValue(container, "txSize")).isEqualTo(10); retry = TestUtils.getPropertyValue(endpoint, "retryTemplate", RetryTemplate.class); assertThat(TestUtils.getPropertyValue(retry, "retryPolicy.maxAttempts")).isEqualTo(23); assertThat(TestUtils.getPropertyValue(retry, "backOffPolicy.initialInterval")).isEqualTo(2000L); assertThat(TestUtils.getPropertyValue(retry, "backOffPolicy.maxInterval")).isEqualTo(20000L); assertThat(TestUtils.getPropertyValue(retry, "backOffPolicy.multiplier")).isEqualTo(5.0); List<?> requestMatchers = TestUtils.getPropertyValue(endpoint, "headerMapper.requestHeaderMatcher.matchers", List.class); assertThat(requestMatchers).hasSize(1); assertThat(TestUtils.getPropertyValue(requestMatchers.get(0), "pattern")).isEqualTo("foo"); return container; }
From source file:org.springframework.xd.dirt.integration.bus.rabbit.RabbitMessageBusTests.java
@Test public void testConsumerProperties() throws Exception { MessageBus bus = getMessageBus();//from www .ja v a2 s .c om Properties properties = new Properties(); properties.put("transacted", "true"); // test transacted with defaults; not allowed with ackmode NONE bus.bindConsumer("props.0", new DirectChannel(), properties); @SuppressWarnings("unchecked") List<Binding> bindings = TestUtils.getPropertyValue(bus, "messageBus.bindings", List.class); assertEquals(1, bindings.size()); AbstractEndpoint endpoint = bindings.get(0).getEndpoint(); SimpleMessageListenerContainer container = TestUtils.getPropertyValue(endpoint, "messageListenerContainer", SimpleMessageListenerContainer.class); assertEquals(AcknowledgeMode.AUTO, container.getAcknowledgeMode()); assertEquals("xdbus.props.0", container.getQueueNames()[0]); assertTrue(TestUtils.getPropertyValue(container, "transactional", Boolean.class)); assertEquals(1, TestUtils.getPropertyValue(container, "concurrentConsumers")); assertNull(TestUtils.getPropertyValue(container, "maxConcurrentConsumers")); assertTrue(TestUtils.getPropertyValue(container, "defaultRequeueRejected", Boolean.class)); assertEquals(1, TestUtils.getPropertyValue(container, "prefetchCount")); assertEquals(1, TestUtils.getPropertyValue(container, "txSize")); Advice retry = TestUtils.getPropertyValue(container, "adviceChain", Advice[].class)[0]; assertEquals(3, TestUtils.getPropertyValue(retry, "retryOperations.retryPolicy.maxAttempts")); assertEquals(1000L, TestUtils.getPropertyValue(retry, "retryOperations.backOffPolicy.initialInterval")); assertEquals(10000L, TestUtils.getPropertyValue(retry, "retryOperations.backOffPolicy.maxInterval")); assertEquals(2.0, TestUtils.getPropertyValue(retry, "retryOperations.backOffPolicy.multiplier")); bus.unbindConsumers("props.0"); assertEquals(0, bindings.size()); properties = new Properties(); properties.put("ackMode", "NONE"); properties.put("backOffInitialInterval", "2000"); properties.put("backOffMaxInterval", "20000"); properties.put("backOffMultiplier", "5.0"); properties.put("concurrency", "2"); properties.put("maxAttempts", "23"); properties.put("maxConcurrency", "3"); properties.put("prefix", "foo."); properties.put("prefetch", "20"); properties.put("requestHeaderPatterns", "foo"); properties.put("requeue", "false"); properties.put("txSize", "10"); properties.put("partitionIndex", 0); bus.bindConsumer("props.0", new DirectChannel(), properties); @SuppressWarnings("unchecked") List<Binding> bindingsNow = TestUtils.getPropertyValue(bus, "messageBus.bindings", List.class); assertEquals(1, bindingsNow.size()); endpoint = bindingsNow.get(0).getEndpoint(); container = verifyContainer(endpoint); assertEquals("foo.props.0", container.getQueueNames()[0]); try { bus.bindPubSubConsumer("dummy", null, properties); fail("Expected exception"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), allOf(containsString("RabbitMessageBus does not support consumer properties: "), containsString("partitionIndex"), containsString("concurrency"), containsString(" for dummy."))); } try { bus.bindConsumer("queue:dummy", null, properties); fail("Expected exception"); } catch (IllegalArgumentException e) { assertEquals("RabbitMessageBus does not support consumer property: partitionIndex for queue:dummy.", e.getMessage()); } bus.unbindConsumers("props.0"); assertEquals(0, bindingsNow.size()); }
From source file:org.springframework.xd.dirt.integration.bus.rabbit.RabbitMessageBusTests.java
private SimpleMessageListenerContainer verifyContainer(AbstractEndpoint endpoint) { SimpleMessageListenerContainer container; Advice retry;//from w w w. j av a 2 s . co m container = TestUtils.getPropertyValue(endpoint, "messageListenerContainer", SimpleMessageListenerContainer.class); assertEquals(AcknowledgeMode.NONE, container.getAcknowledgeMode()); assertThat(container.getQueueNames()[0], startsWith("foo.props.0")); assertFalse(TestUtils.getPropertyValue(container, "transactional", Boolean.class)); assertEquals(2, TestUtils.getPropertyValue(container, "concurrentConsumers")); assertEquals(3, TestUtils.getPropertyValue(container, "maxConcurrentConsumers")); assertFalse(TestUtils.getPropertyValue(container, "defaultRequeueRejected", Boolean.class)); assertEquals(20, TestUtils.getPropertyValue(container, "prefetchCount")); assertEquals(10, TestUtils.getPropertyValue(container, "txSize")); retry = TestUtils.getPropertyValue(container, "adviceChain", Advice[].class)[0]; assertEquals(23, TestUtils.getPropertyValue(retry, "retryOperations.retryPolicy.maxAttempts")); assertEquals(2000L, TestUtils.getPropertyValue(retry, "retryOperations.backOffPolicy.initialInterval")); assertEquals(20000L, TestUtils.getPropertyValue(retry, "retryOperations.backOffPolicy.maxInterval")); assertEquals(5.0, TestUtils.getPropertyValue(retry, "retryOperations.backOffPolicy.multiplier")); List<?> requestMatchers = TestUtils.getPropertyValue(endpoint, "headerMapper.requestHeaderMatcher.strategies", List.class); assertEquals(1, requestMatchers.size()); assertEquals("foo", TestUtils.getPropertyValue(requestMatchers.get(0), "patterns", Collection.class).iterator().next()); return container; }