Example usage for org.springframework.amqp.core MessageDeliveryMode NON_PERSISTENT

List of usage examples for org.springframework.amqp.core MessageDeliveryMode NON_PERSISTENT

Introduction

In this page you can find the example usage for org.springframework.amqp.core MessageDeliveryMode NON_PERSISTENT.

Prototype

MessageDeliveryMode NON_PERSISTENT

To view the source code for org.springframework.amqp.core MessageDeliveryMode NON_PERSISTENT.

Click Source Link

Document

Non persistent.

Usage

From source file:weChat.amqp.JavaConfigFixedReplyQueueTests.java

/**
 * Sends a message to a service that upcases the String and returns as a
 * reply using a {@link RabbitTemplate} configured with a fixed reply queue
 * and reply listener, configured with JavaConfig.
 *//*from  ww w  . ja v  a2s . c o m*/
@Test
public void test() {
    AmqpReqParam param = new AmqpReqParam();
    param.setCmdid("WJ007");
    param.setCompanycode("00111");
    param.setWechatpubinfoid(1);
    BaseDto dto = new BaseDto();
    dto.put("cardnum", "5000028");
    param.setParams(dto);
    AmqpRespParam resp = (AmqpRespParam) rabbitTemplate.convertSendAndReceive(param, (message) -> {
        MessageProperties properities = message.getMessageProperties();
        String corrId = UUID.randomUUID().toString();
        properities.setCorrelationId(corrId.getBytes());
        properities.setDeliveryMode(MessageDeliveryMode.NON_PERSISTENT);
        properities.setTimestamp(new Date());
        long currentTimeMillis = System.currentTimeMillis();
        properities.setMessageId(String.valueOf(currentTimeMillis));

        return message;
    });
    System.out.println(resp);
}

From source file:weChat.amqp.RpcTest.java

/**
 * Sends a message to a service that upcases the String and returns as a
 * reply using a {@link RabbitTemplate} configured with a fixed reply queue
 * and reply listener, configured with JavaConfig.
 *//*  w ww  . j av a2s.co  m*/
@Test
public void test() {
    AmqpReqParam param = new AmqpReqParam();
    param.setCmdid("WJ007");
    param.setCompanycode("01103");
    param.setWechatpubinfoid(1);
    BaseDto dto = new BaseDto();
    dto.put("cardnum", "5000011");
    param.setParams(dto);
    //String corrId = UUID.randomUUID().toString();
    String corrId = FixedReplyQueueConfig.responseQueue;
    Object resp = rabbitTemplate.convertSendAndReceive(FixedReplyQueueConfig.routing, param, (message) -> {
        MessageProperties properities = message.getMessageProperties();

        System.out.println("corrId:" + corrId);
        properities.setCorrelationId(corrId.getBytes());
        properities.setDeliveryMode(MessageDeliveryMode.NON_PERSISTENT);
        properities.setTimestamp(new Date());
        long currentTimeMillis = System.currentTimeMillis();
        properities.setMessageId(String.valueOf(currentTimeMillis));
        properities.setExpiration(String.valueOf(50000));
        properities.setContentEncoding(corrId);

        return message;
    });
    System.out.println("?" + resp);
}

From source file:org.springframework.amqp.rabbit.core.BatchingRabbitTemplateTests.java

@Test
public void testDebatchByContainerPerformance() throws Exception {
    final List<Message> received = new ArrayList<Message>();
    int count = 100000;
    final CountDownLatch latch = new CountDownLatch(count);
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(this.connectionFactory);
    container.setQueueNames(ROUTE);//from w  w w .  j  a  v  a 2 s.  c o  m
    container.setMessageListener((MessageListener) message -> {
        received.add(message);
        latch.countDown();
    });
    container.setReceiveTimeout(100);
    container.setPrefetchCount(1000);
    container.setTxSize(1000);
    container.afterPropertiesSet();
    container.start();
    try {
        BatchingStrategy batchingStrategy = new SimpleBatchingStrategy(1000, Integer.MAX_VALUE, 30000);
        BatchingRabbitTemplate template = new BatchingRabbitTemplate(batchingStrategy, this.scheduler);
        //         RabbitTemplate template = new RabbitTemplate();
        template.setConnectionFactory(this.connectionFactory);
        MessageProperties props = new MessageProperties();
        props.setDeliveryMode(MessageDeliveryMode.NON_PERSISTENT);
        Message message = new Message(new byte[256], props);
        StopWatch watch = new StopWatch();
        watch.start();
        for (int i = 0; i < count; i++) {
            template.send("", ROUTE, message);
        }
        assertTrue(latch.await(60, TimeUnit.SECONDS));
        watch.stop();
        // System .out .println(watch.getTotalTimeMillis());
        assertEquals(count, received.size());
    } finally {
        container.stop();
    }
}

From source file:org.springframework.amqp.rabbit.log4j.AmqpAppenderIntegrationTests.java

@Test
public void testAppender() throws InterruptedException {
    TestListener testListener = (TestListener) applicationContext.getBean("testListener", 4);
    listenerContainer.setMessageListener(testListener);
    listenerContainer.start();/*  www . j ava 2s .c  o m*/

    AmqpAppender appender = (AmqpAppender) log.getParent().getAllAppenders().nextElement();
    assertFalse(appender.isDurable());
    assertEquals(MessageDeliveryMode.NON_PERSISTENT.toString(), appender.getDeliveryMode());

    Logger log = Logger.getLogger(getClass());

    log.debug("This is a DEBUG message");
    log.info("This is an INFO message");
    log.warn("This is a WARN message");
    log.error("This is an ERROR message", new RuntimeException("Test exception"));

    assertTrue(testListener.getLatch().await(5, TimeUnit.SECONDS));
    assertNotNull(testListener.getId());
}

From source file:org.springframework.cloud.stream.binder.rabbit.RabbitBinderTests.java

@Test
public void testProducerProperties() throws Exception {
    RabbitTestBinder binder = getBinder();
    Binding<MessageChannel> producerBinding = binder.bindProducer("props.0",
            createBindableChannel("input", new BindingProperties()), createProducerProperties());
    Lifecycle endpoint = extractEndpoint(producerBinding);
    MessageDeliveryMode mode = TestUtils.getPropertyValue(endpoint, "defaultDeliveryMode",
            MessageDeliveryMode.class);
    assertThat(mode).isEqualTo(MessageDeliveryMode.PERSISTENT);
    List<?> requestHeaders = TestUtils.getPropertyValue(endpoint, "headerMapper.requestHeaderMatcher.matchers",
            List.class);
    assertThat(requestHeaders).hasSize(2);
    producerBinding.unbind();/* w  w w .  jav  a  2s  .co m*/
    assertThat(endpoint.isRunning()).isFalse();
    assertThat(TestUtils.getPropertyValue(endpoint, "amqpTemplate.transactional", Boolean.class)).isFalse();

    ExtendedProducerProperties<RabbitProducerProperties> producerProperties = createProducerProperties();
    producerProperties.getExtension().setPrefix("foo.");
    producerProperties.getExtension().setDeliveryMode(MessageDeliveryMode.NON_PERSISTENT);
    producerProperties.getExtension().setHeaderPatterns(new String[] { "foo" });
    producerProperties.setPartitionKeyExpression(spelExpressionParser.parseExpression("'foo'"));
    producerProperties.setPartitionKeyExtractorClass(TestPartitionKeyExtractorClass.class);
    producerProperties.setPartitionSelectorExpression(spelExpressionParser.parseExpression("0"));
    producerProperties.setPartitionSelectorClass(TestPartitionSelectorClass.class);
    producerProperties.setPartitionCount(1);
    producerProperties.getExtension().setTransacted(true);
    producerProperties.getExtension().setDelayExpression("42");
    producerProperties.setRequiredGroups("prodPropsRequired");

    BindingProperties producerBindingProperties = createProducerBindingProperties(producerProperties);
    DirectChannel channel = createBindableChannel("output", producerBindingProperties);
    producerBinding = binder.bindProducer("props.0", channel, producerProperties);
    endpoint = extractEndpoint(producerBinding);
    assertThat(getEndpointRouting(endpoint))
            .isEqualTo("'props.0-' + headers['" + BinderHeaders.PARTITION_HEADER + "']");
    assertThat(
            TestUtils.getPropertyValue(endpoint, "delayExpression", SpelExpression.class).getExpressionString())
                    .isEqualTo("42");
    mode = TestUtils.getPropertyValue(endpoint, "defaultDeliveryMode", MessageDeliveryMode.class);
    assertThat(mode).isEqualTo(MessageDeliveryMode.NON_PERSISTENT);
    assertThat(TestUtils.getPropertyValue(endpoint, "amqpTemplate.transactional", Boolean.class)).isTrue();
    verifyFooRequestProducer(endpoint);
    channel.send(new GenericMessage<>("foo"));
    org.springframework.amqp.core.Message received = new RabbitTemplate(this.rabbitAvailableRule.getResource())
            .receive("foo.props.0.prodPropsRequired-0", 10_000);
    assertThat(received).isNotNull();
    assertThat(received.getMessageProperties().getReceivedDelay()).isEqualTo(42);

    producerBinding.unbind();
    assertThat(endpoint.isRunning()).isFalse();
}

From source file:org.springframework.cloud.stream.binder.rabbit.RabbitBinderTests.java

private void testAutoBindDLQPartionedConsumerFirstWithRepublishGuts(final boolean withRetry) throws Exception {
    RabbitTestBinder binder = getBinder();
    ExtendedConsumerProperties<RabbitConsumerProperties> properties = createConsumerProperties();
    properties.getExtension().setPrefix("bindertest.");
    properties.getExtension().setAutoBindDlq(true);
    properties.getExtension().setRepublishToDlq(true);
    properties.getExtension().setRepublishDeliveyMode(MessageDeliveryMode.NON_PERSISTENT);
    properties.setMaxAttempts(withRetry ? 2 : 1);
    properties.setPartitioned(true);//from   w w  w. j ava2s  .  c om
    properties.setInstanceIndex(0);
    DirectChannel input0 = createBindableChannel("input", createConsumerBindingProperties(properties));
    input0.setBeanName("test.input0DLQ");
    Binding<MessageChannel> input0Binding = binder.bindConsumer("partPubDLQ.0", "dlqPartGrp", input0,
            properties);
    Binding<MessageChannel> defaultConsumerBinding1 = binder.bindConsumer("partPubDLQ.0", "default",
            new QueueChannel(), properties);
    properties.setInstanceIndex(1);
    DirectChannel input1 = createBindableChannel("input1", createConsumerBindingProperties(properties));
    input1.setBeanName("test.input1DLQ");
    Binding<MessageChannel> input1Binding = binder.bindConsumer("partPubDLQ.0", "dlqPartGrp", input1,
            properties);
    Binding<MessageChannel> defaultConsumerBinding2 = binder.bindConsumer("partPubDLQ.0", "default",
            new QueueChannel(), properties);

    ExtendedProducerProperties<RabbitProducerProperties> producerProperties = createProducerProperties();
    producerProperties.getExtension().setPrefix("bindertest.");
    producerProperties.getExtension().setAutoBindDlq(true);
    producerProperties.setPartitionKeyExtractorClass(PartitionTestSupport.class);
    producerProperties.setPartitionSelectorClass(PartitionTestSupport.class);
    producerProperties.setPartitionCount(2);
    BindingProperties bindingProperties = createProducerBindingProperties(producerProperties);
    DirectChannel output = createBindableChannel("output", bindingProperties);
    output.setBeanName("test.output");
    Binding<MessageChannel> outputBinding = binder.bindProducer("partPubDLQ.0", output, producerProperties);

    final CountDownLatch latch0 = new CountDownLatch(1);
    input0.subscribe(new MessageHandler() {

        @Override
        public void handleMessage(Message<?> message) throws MessagingException {
            if (latch0.getCount() <= 0) {
                throw new RuntimeException("dlq");
            }
            latch0.countDown();
        }

    });

    final CountDownLatch latch1 = new CountDownLatch(1);
    input1.subscribe(new MessageHandler() {

        @Override
        public void handleMessage(Message<?> message) throws MessagingException {
            if (latch1.getCount() <= 0) {
                throw new RuntimeException("dlq");
            }
            latch1.countDown();
        }

    });

    ApplicationContext context = TestUtils.getPropertyValue(binder.getBinder(), "applicationContext",
            ApplicationContext.class);
    SubscribableChannel boundErrorChannel = context.getBean("bindertest.partPubDLQ.0.dlqPartGrp-0.errors",
            SubscribableChannel.class);
    SubscribableChannel globalErrorChannel = context.getBean("errorChannel", SubscribableChannel.class);
    final AtomicReference<Message<?>> boundErrorChannelMessage = new AtomicReference<>();
    final AtomicReference<Message<?>> globalErrorChannelMessage = new AtomicReference<>();
    final AtomicBoolean hasRecovererInCallStack = new AtomicBoolean(!withRetry);
    boundErrorChannel.subscribe(new MessageHandler() {

        @Override
        public void handleMessage(Message<?> message) throws MessagingException {
            boundErrorChannelMessage.set(message);
            String stackTrace = Arrays.toString(new RuntimeException().getStackTrace());
            hasRecovererInCallStack.set(stackTrace.contains("ErrorMessageSendingRecoverer"));
        }

    });
    globalErrorChannel.subscribe(new MessageHandler() {

        @Override
        public void handleMessage(Message<?> message) throws MessagingException {
            globalErrorChannelMessage.set(message);
        }

    });

    output.send(new GenericMessage<>(1));
    assertThat(latch1.await(10, TimeUnit.SECONDS)).isTrue();

    output.send(new GenericMessage<>(0));
    assertThat(latch0.await(10, TimeUnit.SECONDS)).isTrue();

    output.send(new GenericMessage<>(1));

    RabbitTemplate template = new RabbitTemplate(this.rabbitAvailableRule.getResource());
    template.setReceiveTimeout(10000);

    String streamDLQName = "bindertest.partPubDLQ.0.dlqPartGrp.dlq";

    org.springframework.amqp.core.Message received = template.receive(streamDLQName);
    assertThat(received).isNotNull();
    assertThat(received.getMessageProperties().getHeaders().get("x-original-routingKey"))
            .isEqualTo("partPubDLQ.0-1");
    assertThat(received.getMessageProperties().getHeaders()).doesNotContainKey(BinderHeaders.PARTITION_HEADER);
    assertThat(received.getMessageProperties().getReceivedDeliveryMode())
            .isEqualTo(MessageDeliveryMode.NON_PERSISTENT);

    output.send(new GenericMessage<>(0));
    received = template.receive(streamDLQName);
    assertThat(received).isNotNull();
    assertThat(received.getMessageProperties().getHeaders().get("x-original-routingKey"))
            .isEqualTo("partPubDLQ.0-0");
    assertThat(received.getMessageProperties().getHeaders()).doesNotContainKey(BinderHeaders.PARTITION_HEADER);

    // verify we got a message on the dedicated error channel and the global (via bridge)
    assertThat(boundErrorChannelMessage.get()).isNotNull();
    assertThat(globalErrorChannelMessage.get()).isNotNull();
    assertThat(hasRecovererInCallStack.get()).isEqualTo(withRetry);

    input0Binding.unbind();
    input1Binding.unbind();
    defaultConsumerBinding1.unbind();
    defaultConsumerBinding2.unbind();
    outputBinding.unbind();
}

From source file:org.springframework.cloud.stream.binder.rabbit.RabbitBinderTests.java

@SuppressWarnings("unchecked")
@Test//from   ww w .java 2 s. c o m
public void testBatchingAndCompression() throws Exception {
    RabbitTestBinder binder = getBinder();
    ExtendedProducerProperties<RabbitProducerProperties> producerProperties = createProducerProperties();
    producerProperties.getExtension().setDeliveryMode(MessageDeliveryMode.NON_PERSISTENT);
    producerProperties.getExtension().setBatchingEnabled(true);
    producerProperties.getExtension().setBatchSize(2);
    producerProperties.getExtension().setBatchBufferLimit(100000);
    producerProperties.getExtension().setBatchTimeout(30000);
    producerProperties.getExtension().setCompress(true);
    producerProperties.setRequiredGroups("default");

    DirectChannel output = createBindableChannel("input", createProducerBindingProperties(producerProperties));
    output.setBeanName("batchingProducer");
    Binding<MessageChannel> producerBinding = binder.bindProducer("batching.0", output, producerProperties);

    Log logger = spy(TestUtils.getPropertyValue(binder, "binder.compressingPostProcessor.logger", Log.class));
    new DirectFieldAccessor(TestUtils.getPropertyValue(binder, "binder.compressingPostProcessor"))
            .setPropertyValue("logger", logger);
    when(logger.isTraceEnabled()).thenReturn(true);

    assertThat(TestUtils.getPropertyValue(binder, "binder.compressingPostProcessor.level"))
            .isEqualTo(Deflater.BEST_SPEED);

    output.send(new GenericMessage<>("foo".getBytes()));
    output.send(new GenericMessage<>("bar".getBytes()));

    Object out = spyOn("batching.0.default").receive(false);
    assertThat(out).isInstanceOf(byte[].class);
    assertThat(new String((byte[]) out)).isEqualTo("\u0000\u0000\u0000\u0003foo\u0000\u0000\u0000\u0003bar");

    ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(Object.class);
    verify(logger).trace(captor.capture());
    assertThat(captor.getValue().toString()).contains(("Compressed 14 to "));

    QueueChannel input = new QueueChannel();
    input.setBeanName("batchingConsumer");
    Binding<MessageChannel> consumerBinding = binder.bindConsumer("batching.0", "test", input,
            createConsumerProperties());

    output.send(new GenericMessage<>("foo".getBytes()));
    output.send(new GenericMessage<>("bar".getBytes()));

    Message<byte[]> in = (Message<byte[]>) input.receive(10000);
    assertThat(in).isNotNull();
    assertThat(new String(in.getPayload())).isEqualTo("foo");
    in = (Message<byte[]>) input.receive(10000);
    assertThat(in).isNotNull();
    assertThat(new String(in.getPayload())).isEqualTo("bar");
    assertThat(in.getHeaders().get(AmqpHeaders.DELIVERY_MODE)).isNull();

    producerBinding.unbind();
    consumerBinding.unbind();
}

From source file:org.springframework.integration.amqp.config.AmqpOutboundChannelAdapterParserTests.java

@Test
public void withHeaderMapperCustomHeaders() {
    Object eventDrivenConsumer = context.getBean("withHeaderMapperCustomHeaders");

    AmqpOutboundEndpoint endpoint = TestUtils.getPropertyValue(eventDrivenConsumer, "handler",
            AmqpOutboundEndpoint.class);
    assertNotNull(TestUtils.getPropertyValue(endpoint, "defaultDeliveryMode"));
    assertFalse(TestUtils.getPropertyValue(endpoint, "lazyConnect", Boolean.class));
    assertEquals("42", TestUtils
            .getPropertyValue(endpoint, "delayExpression", org.springframework.expression.Expression.class)
            .getExpressionString());//from   w  w  w.  j a  v  a2 s. c om

    Field amqpTemplateField = ReflectionUtils.findField(AmqpOutboundEndpoint.class, "amqpTemplate");
    amqpTemplateField.setAccessible(true);
    RabbitTemplate amqpTemplate = TestUtils.getPropertyValue(endpoint, "amqpTemplate", RabbitTemplate.class);
    amqpTemplate = Mockito.spy(amqpTemplate);
    final AtomicBoolean shouldBePersistent = new AtomicBoolean();

    Mockito.doAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        org.springframework.amqp.core.Message amqpMessage = (org.springframework.amqp.core.Message) args[2];
        MessageProperties properties = amqpMessage.getMessageProperties();
        assertEquals("foo", properties.getHeaders().get("foo"));
        assertEquals("foobar", properties.getHeaders().get("foobar"));
        assertNull(properties.getHeaders().get("bar"));
        assertEquals(
                shouldBePersistent.get() ? MessageDeliveryMode.PERSISTENT : MessageDeliveryMode.NON_PERSISTENT,
                properties.getDeliveryMode());
        return null;
    }).when(amqpTemplate).send(Mockito.any(String.class), Mockito.any(String.class),
            Mockito.any(org.springframework.amqp.core.Message.class), Mockito.any(CorrelationData.class));
    ReflectionUtils.setField(amqpTemplateField, endpoint, amqpTemplate);

    MessageChannel requestChannel = context.getBean("requestChannel", MessageChannel.class);
    Message<?> message = MessageBuilder.withPayload("hello").setHeader("foo", "foo").setHeader("bar", "bar")
            .setHeader("foobar", "foobar").build();
    requestChannel.send(message);
    Mockito.verify(amqpTemplate, Mockito.times(1)).send(anyString(), isNull(),
            Mockito.any(org.springframework.amqp.core.Message.class), isNull());

    shouldBePersistent.set(true);
    message = MessageBuilder.withPayload("hello").setHeader("foo", "foo").setHeader("bar", "bar")
            .setHeader("foobar", "foobar").setHeader(AmqpHeaders.DELIVERY_MODE, MessageDeliveryMode.PERSISTENT)
            .build();
    requestChannel.send(message);
}

From source file:org.springframework.xd.dirt.integration.bus.rabbit.RabbitMessageBusTests.java

@Test
public void testProducerProperties() throws Exception {
    MessageBus bus = getMessageBus();/*w  ww  . j ava2  s  .c  o m*/
    bus.bindProducer("props.0", new DirectChannel(), null);
    @SuppressWarnings("unchecked")
    List<Binding> bindings = TestUtils.getPropertyValue(bus, "messageBus.bindings", List.class);
    assertEquals(1, bindings.size());
    AbstractEndpoint endpoint = bindings.get(0).getEndpoint();
    assertEquals("xdbus.props.0", TestUtils.getPropertyValue(endpoint, "handler.delegate.routingKey"));
    MessageDeliveryMode mode = TestUtils.getPropertyValue(endpoint, "handler.delegate.defaultDeliveryMode",
            MessageDeliveryMode.class);
    assertEquals(MessageDeliveryMode.PERSISTENT, mode);
    List<?> requestHeaders = TestUtils.getPropertyValue(endpoint,
            "handler.delegate.headerMapper.requestHeaderMatcher.strategies", List.class);
    assertEquals(2, requestHeaders.size());
    bus.unbindProducers("props.0");
    assertEquals(0, bindings.size());

    Properties properties = new Properties();
    properties.put("prefix", "foo.");
    properties.put("deliveryMode", "NON_PERSISTENT");
    properties.put("requestHeaderPatterns", "foo");
    properties.put("partitionKeyExpression", "'foo'");
    properties.put("partitionKeyExtractorClass", "foo");
    properties.put("partitionSelectorExpression", "0");
    properties.put("partitionSelectorClass", "foo");
    properties.put(BusProperties.NEXT_MODULE_COUNT, "1");

    bus.bindProducer("props.0", new DirectChannel(), properties);
    assertEquals(1, bindings.size());
    endpoint = bindings.get(0).getEndpoint();
    assertEquals("'foo.props.0-' + headers['partition']",
            TestUtils.getPropertyValue(endpoint, "handler.delegate.routingKeyExpression", SpelExpression.class)
                    .getExpressionString());
    mode = TestUtils.getPropertyValue(endpoint, "handler.delegate.defaultDeliveryMode",
            MessageDeliveryMode.class);
    assertEquals(MessageDeliveryMode.NON_PERSISTENT, mode);
    verifyFooRequestProducer(endpoint);

    try {
        bus.bindPubSubProducer("dummy", new DirectChannel(), properties);
        fail("Expected exception");
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(),
                allOf(containsString("RabbitMessageBus does not support producer properties: "),
                        containsString("partitionSelectorExpression"),
                        containsString("partitionKeyExtractorClass"), containsString("partitionKeyExpression"),
                        containsString("partitionSelectorClass")));
        assertThat(e.getMessage(), containsString("for dummy."));
    }
    try {
        bus.bindProducer("queue:dummy", new DirectChannel(), properties);
        fail("Expected exception");
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(),
                allOf(containsString("RabbitMessageBus does not support producer properties: "),
                        containsString("partitionSelectorExpression"),
                        containsString("partitionKeyExtractorClass"), containsString("partitionKeyExpression"),
                        containsString("partitionSelectorClass")));
        assertThat(e.getMessage(), containsString("for queue:dummy."));
    }

    bus.unbindProducers("props.0");
    assertEquals(0, bindings.size());
}

From source file:org.springframework.xd.dirt.integration.bus.rabbit.RabbitMessageBusTests.java

@Test
public void testRequestReplyRequestorProperties() throws Exception {
    MessageBus bus = getMessageBus();// w  w  w .j ava  2 s . co m
    Properties properties = new Properties();
    properties.put("prefix", "foo.");
    properties.put("deliveryMode", "NON_PERSISTENT");

    properties.put("requestHeaderPatterns", "foo");
    properties.put("replyHeaderPatterns", "bar");

    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("requeue", "false");
    properties.put("txSize", "10");

    bus.bindRequestor("props.0", new DirectChannel(), new DirectChannel(), properties);
    @SuppressWarnings("unchecked")
    List<Binding> bindings = TestUtils.getPropertyValue(bus, "messageBus.bindings", List.class);

    assertEquals(2, bindings.size());
    AbstractEndpoint endpoint = bindings.get(0).getEndpoint(); // producer
    assertEquals("foo.props.0.requests", TestUtils.getPropertyValue(endpoint, "handler.delegate.routingKey"));
    MessageDeliveryMode mode = TestUtils.getPropertyValue(endpoint, "handler.delegate.defaultDeliveryMode",
            MessageDeliveryMode.class);
    assertEquals(MessageDeliveryMode.NON_PERSISTENT, mode);
    verifyFooRequestBarReplyProducer(endpoint);

    endpoint = bindings.get(1).getEndpoint(); // consumer

    verifyContainer(endpoint);

    verifyBarReplyConsumer(endpoint);

    properties.put("partitionKeyExpression", "'foo'");
    properties.put("partitionKeyExtractorClass", "foo");
    properties.put("partitionSelectorExpression", "0");
    properties.put("partitionSelectorClass", "foo");
    properties.put(BusProperties.NEXT_MODULE_COUNT, "1");
    properties.put("partitionIndex", "0");
    try {
        bus.bindRequestor("dummy", null, null, properties);
        fail("Expected exception");
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(),
                allOf(containsString("RabbitMessageBus does not support producer properties: "),
                        containsString("partitionSelectorExpression"),
                        containsString("partitionKeyExtractorClass"), containsString("partitionKeyExpression"),
                        containsString("partitionSelectorClass")));
        assertThat(e.getMessage(), allOf(containsString("partitionIndex"), containsString("for dummy.")));
    }

    bus.unbindConsumers("props.0");
    bus.unbindProducers("props.0");
    assertEquals(0, bindings.size());
}