Example usage for org.springframework.integration.amqp.channel PublishSubscribeAmqpChannel PublishSubscribeAmqpChannel

List of usage examples for org.springframework.integration.amqp.channel PublishSubscribeAmqpChannel PublishSubscribeAmqpChannel

Introduction

In this page you can find the example usage for org.springframework.integration.amqp.channel PublishSubscribeAmqpChannel PublishSubscribeAmqpChannel.

Prototype

public PublishSubscribeAmqpChannel(String channelName, AbstractMessageListenerContainer container,
        AmqpTemplate amqpTemplate) 

Source Link

Document

Construct an instance with the supplied name, container and template; default header mappers will be used if the message is mapped.

Usage

From source file:org.springframework.integration.amqp.channel.DispatcherHasNoSubscribersTests.java

@Test
public void testPubSub() {
    final Channel channel = mock(Channel.class);
    Connection connection = mock(Connection.class);
    doAnswer(new Answer<Channel>() {
        public Channel answer(InvocationOnMock invocation) throws Throwable {
            return channel;
        }/*from w w  w.j  a  v a 2s  .  c o m*/
    }).when(connection).createChannel(anyBoolean());
    ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
    when(connectionFactory.createConnection()).thenReturn(connection);
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
    container.setConnectionFactory(connectionFactory);
    AmqpTemplate amqpTemplate = mock(AmqpTemplate.class);
    final Queue queue = new Queue("noSubscribersQueue");
    PublishSubscribeAmqpChannel amqpChannel = new PublishSubscribeAmqpChannel("noSubscribersChannel", container,
            amqpTemplate) {
        @Override
        protected Queue initializeQueue(AmqpAdmin admin, String channelName) {
            return queue;
        }
    };
    amqpChannel.setBeanName("noSubscribersChannel");
    amqpChannel.afterPropertiesSet();

    List<String> logList = insertMockLoggerInListener(amqpChannel);
    MessageListener listener = (MessageListener) container.getMessageListener();
    listener.onMessage(new Message("Hello world!".getBytes(), null));
    verifyLogReceived(logList);
}