Package org.springframework.amqp.rabbit.listener

Examples of org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer


                                    + "while the Container for that queue was already processing events. "
                                    + "This may lead to Events not being published to all Clusters",
                            queueName);
            }
        } else {
            SimpleMessageListenerContainer newContainer = createContainer(amqpConfig);
            newContainer.setQueueNames(queueName);
            newContainer.setMessageListener(new ClusterMessageListener(cluster, messageConverter));
            containerPerQueue.put(queueName, newContainer);
            if (started) {
                newContainer.start();
            }
        }
    }
View Full Code Here


     *
     * @param config The container-specific configuration for the new container
     * @return a fully initialized (but not started!) SimpleMessageListenerContainer instance.
     */
    public SimpleMessageListenerContainer createContainer(SpringAMQPConsumerConfiguration config) {
        SimpleMessageListenerContainer newContainer = rabbitMqStrategy.createContainer();
        newContainer.setConnectionFactory(connectionFactory);
        if (config.getTransactionManager() != null) {
            newContainer.setChannelTransacted(true);
            newContainer.setTransactionManager(config.getTransactionManager());
        }
        if (config.getErrorHandler() != null) {
            newContainer.setErrorHandler(config.getErrorHandler());
        }
        if (config.getPrefetchCount() != null) {
            newContainer.setPrefetchCount(config.getPrefetchCount());
        }
        if (config.getTxSize() != null) {
            newContainer.setTxSize(config.getTxSize());
        }
        if (config.getAdviceChain() != null) {
            newContainer.setAdviceChain(config.getAdviceChain());
        }
        if (config.getRecoveryInterval() != null) {
            newContainer.setRecoveryInterval(config.getRecoveryInterval());
        }
        if (config.getConcurrentConsumers() != null) {
            newContainer.setConcurrentConsumers(config.getConcurrentConsumers());
        }
        if (config.getReceiveTimeout() != null) {
            newContainer.setReceiveTimeout(config.getReceiveTimeout());
        }
        if (config.getShutdownTimeout() != null) {
            newContainer.setShutdownTimeout(config.getShutdownTimeout());
        }
        if (config.getTaskExecutor() != null) {
            newContainer.setTaskExecutor(config.getTaskExecutor());
        }
        if (config.getTransactionAttribute() != null) {
            newContainer.setTransactionAttribute(config.getTransactionAttribute());
        }
        if (config.getMessagePropertiesConverter() != null) {
            newContainer.setMessagePropertiesConverter(config.getMessagePropertiesConverter());
        }
        if (config.getAcknowledgeMode() != null) {
            newContainer.setAcknowledgeMode(config.getAcknowledgeMode());
        }
        if (config.getExclusive() != null) {
            rabbitMqStrategy.setExclusive(newContainer, config.getExclusive());
        }
        newContainer.afterPropertiesSet();
        return newContainer;
    }
View Full Code Here

        }
    }

    @Override
    public SimpleMessageListenerContainer createContainer() {
        return new SimpleMessageListenerContainer();
    }
View Full Code Here

  @Override
  public Object invokeMethod(String methodName, Object args) {
    if (CONSUME.equals(methodName)) {
      Consume consume = new Consume();
      SimpleMessageListenerContainer listenerContainer = consume.getListenerContainer();
      Object[] params = (Object[]) args;
      for (Object param : params) {
        if (param instanceof Map) {
          Map paramMap = (Map) param;

          if (paramMap.containsKey(ON_MESSAGE)) {
            Object onMessage = paramMap.get(ON_MESSAGE);
            if (onMessage instanceof String) {
              consume.setEventName((String) onMessage);
            } else if (onMessage instanceof Closure) {
              consume.setDelegate((Closure) onMessage);
            } else if (onMessage instanceof MessageListener) {
              listenerContainer.setMessageListener(onMessage);
            } else {
              listenerContainer.setMessageListener(new MessageListenerAdapter(onMessage));
            }
          }

          if (paramMap.containsKey(ACK)) {
            AcknowledgeMode mode = AcknowledgeMode.valueOf(paramMap.get(ACK).toString().toUpperCase());
            listenerContainer.setAcknowledgeMode(mode);
          } else {
            listenerContainer.setAcknowledgeMode(AcknowledgeMode.AUTO);
          }

        } else if (param instanceof Closure) {
          consume.setDelegate((Closure) param);
        }
      }
      listenerContainer.setQueues(currentQueue);
      listenerContainer.afterPropertiesSet();
      listenerContainer.start();
      listenerContainers.add(listenerContainer);

      return super.invokeMethod(methodName, consume);
    } else if (PUBLISH.equals(methodName)) {
      Publish publish = new Publish();
View Full Code Here

        PowerMockito.doNothing().when(mockContainer).afterPropertiesSet();
    }

    @Test
    public void testListenerContainerKeepsDefaults() throws Exception {
        SimpleMessageListenerContainer actual = testSubject.createContainer(new SpringAMQPConsumerConfiguration());

        // just to make sure PowerMock was correctly configured
        assertSame(mockContainer, actual);

        verify(mockContainer).setConnectionFactory(mockConnectionFactory);
View Full Code Here

        config.setTransactionAttribute(transactionAttribute);
        PlatformTransactionManager mockTransactionManager = mock(PlatformTransactionManager.class);
        config.setTransactionManager(mockTransactionManager);
        config.setTxSize(100);

        SimpleMessageListenerContainer actual = testSubject.createContainer(config);

        // just to make sure PowerMock was correctly configured
        assertSame(mockContainer, actual);

        verify(mockContainer).setAcknowledgeMode(AcknowledgeMode.AUTO);
View Full Code Here

     
    } catch (IOException e) {
      throw new RuntimeException("Failed to create reply to queue", e);
    }
   
    _container = new SimpleMessageListenerContainer();
    _container.setConnectionFactory(connectionFactory);
    _container.setQueueNames(_replyToQueue);
    _container.setMessageListener(this);
  }
View Full Code Here

        private MessageConverter msgConverter;
        private SimpleMessageListenerContainer listenerContainer;
        private static final long DEFAULT_TIMEOUT_MILLIS = 1000;

        public RabbitMQMessageListener(SpringAMQPEndpoint endpoint) {
            this.listenerContainer = new SimpleMessageListenerContainer();
            this.listenerContainer.setTaskExecutor(new SpringAMQPExecutor(endpoint));

            RabbitTemplate template = (RabbitTemplate) endpoint.getAmqpTemplate();
            if(template != null) {
                this.msgConverter = template.getMessageConverter();
View Full Code Here

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class StockProcessor {
  public static void main(String... args) {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(StockProcessorConfiguration.class);
    SimpleMessageListenerContainer container = (SimpleMessageListenerContainer) context.getBean("listenerContainer");
    StockLookup lookup = (StockLookup) context.getBean("stockLookup");
    container.setMessageListener(lookup);
  }
View Full Code Here

@Configuration
public class StockProcessorConfiguration extends CommonConfiguration{
  @Bean
  public SimpleMessageListenerContainer listenerContainer() {
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
    container.setConnectionFactory(connectionFactory());
    container.setQueueName(this.queueName);
    return container;
  }
View Full Code Here

TOP

Related Classes of org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.