Example usage for org.springframework.amqp.rabbit.listener SimpleMessageListenerContainer setConsumerArguments

List of usage examples for org.springframework.amqp.rabbit.listener SimpleMessageListenerContainer setConsumerArguments

Introduction

In this page you can find the example usage for org.springframework.amqp.rabbit.listener SimpleMessageListenerContainer setConsumerArguments.

Prototype

public void setConsumerArguments(Map<String, Object> args) 

Source Link

Document

Set consumer arguments.

Usage

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

@SuppressWarnings("unchecked")
@Test/*from  ww w . j  a  v  a2  s . c om*/
public void testConsumerArgs() throws Exception {
    ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
    Connection connection = mock(Connection.class);
    Channel channel = mock(Channel.class);
    when(connectionFactory.createConnection()).thenReturn(connection);
    when(connection.createChannel(false)).thenReturn(channel);
    final AtomicReference<Consumer> consumer = new AtomicReference<Consumer>();
    final AtomicReference<Map<?, ?>> args = new AtomicReference<Map<?, ?>>();
    doAnswer(invocation -> {
        consumer.set((Consumer) invocation.getArguments()[6]);
        consumer.get().handleConsumeOk("foo");
        args.set((Map<?, ?>) invocation.getArguments()[5]);
        return "foo";
    }).when(channel).basicConsume(anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(),
            any(Map.class), any(Consumer.class));

    final SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory);
    container.setQueueNames("foo");
    container.setMessageListener((MessageListener) message -> {
    });
    container.setConsumerArguments(Collections.<String, Object>singletonMap("x-priority", Integer.valueOf(10)));
    container.afterPropertiesSet();
    container.start();
    verify(channel).basicConsume(anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(),
            any(Map.class), any(Consumer.class));
    assertTrue(args.get() != null);
    assertEquals(10, args.get().get("x-priority"));
    consumer.get().handleCancelOk("foo");
    container.stop();
}