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

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

Introduction

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

Prototype

public void setMessageListener(MessageListener messageListener) 

Source Link

Document

Set the MessageListener .

Usage

From source file:org.farrukh.examples.amqp.Application.java

/**
 * Simple message listener container//from w  w  w .  jav  a2 s. c  o  m
 * @param connectionFactory - RabbitMQ connection factory.
 * @param configuration - Custom application information.
 * @param messageListener - The message listener with delegate object in the adapter.
 * @return
 */
@Bean
public SimpleMessageListenerContainer messageListenerContainer(final ConnectionFactory connectionFactory,
        final ApplicationProperties configuration, final MessageListener messageListener) {
    SimpleMessageListenerContainer messageListenerContainer = new SimpleMessageListenerContainer(
            connectionFactory);
    messageListenerContainer.addQueueNames(configuration.getQueueName());
    messageListenerContainer.setMessageListener(messageListener);
    return messageListenerContainer;
}

From source file:lab.example.service.MessageListener.java

@Bean
SimpleMessageListenerContainer listenerContainer(ConnectionFactory connectionFactory,
        MessageListenerAdapter listenerAdapter) {
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
    container.setConnectionFactory(connectionFactory);
    container.setQueueNames(personEventsQueueName);
    container.setMessageListener(listenerAdapter);

    return container;
}

From source file:com.vcredit.lrh.backend.RabbitConfiguration.java

@Bean
public SimpleMessageListenerContainer appLogContainer(ConnectionFactory connectionFactory) {

    if (!StringUtils.isEmpty(rabbitMQProperties.getLogQueue())) {
        MessageListenerAdapter listener = new MessageListenerAdapter(aPPLogMessageReceiver, "receiveMessage");
        SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
        container.setConnectionFactory(connectionFactory);
        container.setQueueNames(rabbitMQProperties.getLogQueue());
        container.setMessageListener(listener);
        return container;
    } else {// w  w w . ja va  2s. c  o m
        return null;
    }

}

From source file:com.vcredit.lrh.backend.RabbitConfiguration.java

@Bean
public SimpleMessageListenerContainer scheduleTaskContainer(ConnectionFactory connectionFactory) {
    if (!StringUtils.isEmpty(rabbitMQProperties.getScheduleTaskQueue())) {
        MessageListenerAdapter listener1 = new MessageListenerAdapter(scheduleTaskMessageReceiver,
                "receiveMessage");
        SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
        container.setConnectionFactory(connectionFactory);
        container.setQueueNames(rabbitMQProperties.getScheduleTaskQueue());
        container.setMessageListener(listener1);
        return container;
    } else {//  w w w  .j  a  va2s  .co m
        return null;
    }
}

From source file:com.jbrisbin.vpc.jobsched.batch.BatchMessageHandler.java

public BatchMessage handleMessage(BatchMessage batch) throws Exception {
    log.debug("handling message: " + batch.toString());

    final BatchMessage results = new BatchMessage();
    results.setId(batch.getId());//from  ww w.j  a va2  s. c om

    // For waiting till our results are all back
    final CountDownLatch latch = new CountDownLatch(batch.getMessages().size());

    Queue resultsQueue = rabbitAdmin.declareQueue();
    SimpleMessageListenerContainer listener = new SimpleMessageListenerContainer(connectionFactory);
    listener.setAutoAck(true);
    listener.setQueues(resultsQueue);
    listener.setMessageListener(new MessageListener() {
        public void onMessage(Message message) {
            String messageId = new String(message.getMessageProperties().getCorrelationId());
            String body = new String(message.getBody());
            results.getMessages().put(messageId, body);
            latch.countDown();
        }
    });
    listener.start();

    for (Map.Entry<String, String> msg : batch.getMessages().entrySet()) {
        final String[] parts = msg.getKey().split(":");
        template.send(parts[0], parts[1],
                new MessageCreator(parts[2], parts[3], resultsQueue.getName(), msg.getValue().getBytes()));
    }

    // Wait the timeout value per message for all results to be collected
    latch.await((batch.getTimeout() * batch.getMessages().size()), TimeUnit.MINUTES);

    return results;
}

From source file:de.msg.message.amqp.AmqpConfiguration.java

@Bean
public SimpleMessageListenerContainer container(ConnectionFactory connectionFactory,
        MessageListenerAdapter listenerAdapter, MessageConverter jsonMessageConverter) {
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
    container.setConnectionFactory(connectionFactory);
    container.setQueueNames(QUEUE_NAME);
    container.setMessageConverter(jsonMessageConverter);
    container.setMessageListener(listenerAdapter);
    return container;
}

From source file:com.sample.amqp.RabbitConfiguration.java

@Bean
public SimpleMessageListenerContainer listenerContainer() {
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
    container.setConcurrentConsumers(5);
    container.setConnectionFactory(connectionFactory());
    container.setQueues(responseQueue());
    container.setMessageListener(rabbitTemplate());
    return container;
}

From source file:com.bbytes.zorba.messaging.rabbitmq.listener.impl.QueueNotificationHandler.java

@Override
public void handleZorbaRequest(ZorbaRequest request) throws MessagingException {
    if (request == null)
        return;//from   w  w  w . j  a v a 2 s.  c  om
    ZorbaData<String, Serializable> data = request.getData();
    if (data == null) {
        LOG.error("No data received along with request " + request.getId());
        return;
    }
    String queueName = (String) data.get("queueName");
    if (queueName == null || queueName.isEmpty()) {
        LOG.error("No Queue Name received along with request " + request.getId());
        return;
    }
    String event = (String) data.get("event");
    if (event.equals("CREATED")) {
        LOG.debug("New Queue Created. Adding Listener to that");
        final SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
        container.setAutoStartup(false);
        container.setConnectionFactory(rabbitConnectionFactory);
        container.setQueueNames(queueName);
        container.setMessageListener(
                new ZorbaRuntimeRequestHandlerImpl(jsonMessageConverter, zorbaRquestDelegationService));
        container.setConcurrentConsumers(3);
        queueListeners.put(queueName, container);
        // start the container
        Thread thread = new Thread() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                container.start();
            }
        };
        LOG.debug("Starting container for the queue " + queueName);
        thread.start();

    } else if (event.equals("DELETED")) {
        LOG.debug("Deleting container for the queue " + queueName);
        SimpleMessageListenerContainer container = queueListeners.get(queueName);
        if (container == null) {
            LOG.warn("SimpleMessageListenerContainer is null. Why?");
            return;
        }
        if (container.isRunning()) {
            container.stop();
        }
        container.destroy();
        queueListeners.remove(queueName);
    }

}

From source file:limey.git.amqp.SampleAmqpSimpleApplication.java

@Bean
public SimpleMessageListenerContainer container() {
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(this.connectionFactory);
    Object listener = new Object() {
        @SuppressWarnings("unused")
        public void handleMessage(String foo) {
            System.out.println(foo);
        }/*from   ww  w  .  j  a va2s .  c o  m*/
    };
    MessageListenerAdapter adapter = new MessageListenerAdapter(listener);
    container.setMessageListener(adapter);
    container.setQueueNames("foo");
    return container;
}

From source file:crawler.configuration.rabbitmq.RabbitMQConfiguration.java

@Bean
SimpleMessageListenerContainer container(ConnectionFactory connectionFactory) {
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
    container.setConnectionFactory(connectionFactory);
    container.setQueueNames(htmlQueue().getName());
    container.setMessageListener(this);
    container.setConcurrentConsumers(rabbitMQConfigurationProperties.getConcurrentConsumers());
    // container.setMaxConcurrentConsumers(32);
    container.setPrefetchCount(rabbitMQConfigurationProperties.getPrefetchCount());
    // rabbitListenerContainerFactory.setConcurrentConsumers(16);
    return container;
}