Example usage for org.springframework.amqp.rabbit.listener.adapter MessageListenerAdapter MessageListenerAdapter

List of usage examples for org.springframework.amqp.rabbit.listener.adapter MessageListenerAdapter MessageListenerAdapter

Introduction

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

Prototype

public MessageListenerAdapter(Object delegate, String defaultListenerMethod) 

Source Link

Document

Create a new MessageListenerAdapter for the given delegate while also declaring its POJO method.

Usage

From source file:io.acme.solution.application.conf.CommandBusConfigurer.java

@PostConstruct
private void setup() {

    Queue currentQueue = null;//www  . j a  va 2 s  . com
    String currentCommandType = null;
    SimpleMessageListenerContainer currentContainer = null;
    MessageListenerAdapter currentAdapter = null;

    final RabbitAdmin rabbitAdmin = this.context.getBean("commandBusRabbitAdmin", RabbitAdmin.class);
    final ConnectionFactory connectionFactory = this.context.getBean("commandBusConnectionFactory",
            ConnectionFactory.class);
    final TopicExchange exchange = this.context.getBean("commandExchange", TopicExchange.class);
    final MessageConverter converter = this.context.getBean("commandBusMessageConverter",
            MessageConverter.class);
    final Map<String, CommandHandler> commandHandlersRegistry = CommandHandlerUtils
            .buildCommandHandlersRegistry(this.handlerBasePackage, this.context);
    final ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(
            false);
    scanner.addIncludeFilter(new AssignableTypeFilter(Command.class));

    for (BeanDefinition bean : scanner.findCandidateComponents(this.commandBasePackage)) {
        currentCommandType = bean.getBeanClassName().substring(bean.getBeanClassName().lastIndexOf('.') + 1);
        rabbitAdmin.declareQueue(currentQueue = new Queue(this.queuePrefix + currentCommandType));
        rabbitAdmin.declareBinding(BindingBuilder.bind(currentQueue).to(exchange).with(currentCommandType));

        if (commandHandlersRegistry.containsKey(bean.getBeanClassName())) {
            currentAdapter = new MessageListenerAdapter(commandHandlersRegistry.get(bean.getBeanClassName()),
                    converter);

            currentContainer = new SimpleMessageListenerContainer(connectionFactory);
            currentContainer.setMessageListener(currentAdapter);
            currentContainer.setQueues(currentQueue);
            currentContainer.start();
        }
    }

}

From source file:org.openbaton.common.vnfm_sdk.amqp.configuration.RabbitConfiguration.java

@Bean
MessageListenerAdapter listenerAdapter_nfvoGenericActions(AbstractVnfmSpringAmqp receiver) {
    return new MessageListenerAdapter(receiver, "onAction");
}

From source file:org.openbaton.common.vnfm_sdk.amqp.configuration.RabbitConfiguration.java

@Bean
MessageListenerAdapter listenerAdapter_emsRegistrator() {
    if (registrator != null)
        return new MessageListenerAdapter(registrator, "register");
    else/*  www.j  a  v a 2s .  c  om*/
        return null;
}

From source file:org.openbaton.nse.api.EventReceiver.java

@Bean
public MessageListenerAdapter setCreationMessageListenerAdapter() {
    return new MessageListenerAdapter(this, "receiveConfiguration");
}

From source file:org.openbaton.nse.api.EventReceiver.java

@Bean
public MessageListenerAdapter setErrorMessageListenerAdapter() {
    return new MessageListenerAdapter(this, "deleteConfiguration");
}

From source file:org.openbaton.nse.api.EventReceiver.java

@Bean
public MessageListenerAdapter setScaleMessageListenerAdapter() {
    return new MessageListenerAdapter(this, "scaleConfiguration");
}

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

public static void main(String[] args) throws InterruptedException {
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory("localhost");
    connectionFactory.setHost("localhost");
    connectionFactory.setUsername("guest");
    connectionFactory.setPassword("guest");
    assertNotNull(connectionFactory);/*from  ww  w. java  2  s. c  om*/

    MessageConverter messageConverter = new SimpleMessageConverter();
    MessageProperties messageProperties = new MessageProperties();
    messageProperties.setContentType(MessageProperties.CONTENT_TYPE_TEXT_PLAIN);

    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
    container.setConnectionFactory(connectionFactory);
    container.setQueueNames("foo");
    container.setPrefetchCount(1000);
    container.setTxSize(500);
    container.setAcknowledgeMode(AcknowledgeMode.AUTO);
    container.setConcurrentConsumers(20);
    container.setMessageListener(new MessageListenerAdapter(new SimpleAdapter(), messageConverter));
    container.start();

    RabbitTemplate template = new RabbitTemplate(connectionFactory);
    template.setMessageConverter(messageConverter);
    List<BlockingQueue<?>> queues = getQueues(container);

    Thread.sleep(10000);
    int n = 0;
    while (true) {
        for (int i = 1; i <= 200; i++) {

            template.send("foo", "",
                    new Message(
                            "foo # ID: id".replace("#", String.valueOf(i))
                                    .replace("id", java.util.UUID.randomUUID().toString()).getBytes(),
                            messageProperties));

        }
        Thread.sleep(1000);
        if (++n % 10 == 0) {
            logger.warn(count(queues));
        }
    }
}