Example usage for org.springframework.amqp.core AcknowledgeMode NONE

List of usage examples for org.springframework.amqp.core AcknowledgeMode NONE

Introduction

In this page you can find the example usage for org.springframework.amqp.core AcknowledgeMode NONE.

Prototype

AcknowledgeMode NONE

To view the source code for org.springframework.amqp.core AcknowledgeMode NONE.

Click Source Link

Document

No acks - autoAck=true in Channel.basicConsume() .

Usage

From source file:org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainerTests.java

@Test
public void testInconsistentTransactionConfiguration() throws Exception {
    final SingleConnectionFactory singleConnectionFactory = new SingleConnectionFactory("localhost");
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(singleConnectionFactory);
    container.setMessageListener(new MessageListenerAdapter(this));
    container.setQueueNames("foo");
    container.setChannelTransacted(false);
    container.setAcknowledgeMode(AcknowledgeMode.NONE);
    container.setTransactionManager(new TestTransactionManager());
    expectedException.expect(IllegalStateException.class);
    container.afterPropertiesSet();/* w w  w  .j a v  a2  s .c om*/
    container.stop();
    singleConnectionFactory.destroy();
}

From source file:org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainerTests.java

@Test
public void testInconsistentAcknowledgeConfiguration() throws Exception {
    final SingleConnectionFactory singleConnectionFactory = new SingleConnectionFactory("localhost");
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(singleConnectionFactory);
    container.setMessageListener(new MessageListenerAdapter(this));
    container.setQueueNames("foo");
    container.setChannelTransacted(true);
    container.setAcknowledgeMode(AcknowledgeMode.NONE);
    expectedException.expect(IllegalStateException.class);
    container.afterPropertiesSet();//from   ww  w. ja  v  a2s .c om
    container.stop();
    singleConnectionFactory.destroy();
}

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();//from w  w w .j  ava  2 s  .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   ww w  .  ja  v  a  2  s  .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

private SimpleMessageListenerContainer verifyContainer(AbstractEndpoint endpoint) {
    SimpleMessageListenerContainer container;
    Advice retry;// w  ww  .  j a  va  2s . com
    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;
}