Java Code Examples for org.springframework.jms.listener.DefaultMessageListenerContainer#initialize()

The following examples show how to use org.springframework.jms.listener.DefaultMessageListenerContainer#initialize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JmsContainerManagerImpl.java    From c2mon with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Returns the container so that it can be started manually when added during
 * server runtime.
 * @param process the Process to create a container for
 * @param consumersMax the max number of consumers (at start-up subscribe with less)
 * @return the JMS container that was created
 */
private DefaultMessageListenerContainer subscribe(final Process process, final int consumersMax) {
  DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
  container.setConnectionFactory(updateConnectionFactory);
  container.setDestination(new ActiveMQQueue(properties.getJms().getQueuePrefix() + ".update." + process.getName()));
  container.setMessageListener(listener);
  container.setConcurrentConsumers(properties.getJms().getUpdate().getInitialConsumers());
  container.setMaxConcurrentConsumers(consumersMax);
  container.setSessionTransacted(properties.getJms().getUpdate().isTransacted());
  container.setCacheLevel(DefaultMessageListenerContainer.CACHE_CONSUMER);
  container.setAutoStartup(false);
  container.setPhase(ServerConstants.PHASE_START_LAST);
  container.setMaxMessagesPerTask(properties.getJms().getUpdate().getMaxMessagesPerTask());
  container.setReceiveTimeout(properties.getJms().getUpdate().getReceiveTimeout());
  container.setIdleTaskExecutionLimit(properties.getJms().getUpdate().getIdleTaskExecutionLimit());
  container.setBeanName(process.getName() + " update JMS container");
  container.setTaskExecutor(daqThreadPoolTaskExecutor);
  container.setAcceptMessagesWhileStopping(false);
  jmsContainers.put(process.getId(), container);
  container.initialize();
  return container;
}
 
Example 2
Source File: AbstractConsumer.java    From jim-framework with Apache License 2.0 5 votes vote down vote up
public void afterPropertiesSet() {
    if(this.consumerConfig.getBrokerUrlList() != null && !this.consumerConfig.getBrokerUrlList().isEmpty() && !Strings.isNullOrEmpty(this.consumerConfig.getQueueName())) {

        for(String brokerUrl : this.consumerConfig.getBrokerUrlList()) {
            //ConnectionFactory connectionFactory = ConnectionFactoryContainer.getSingleConsumerConnectionFactory(brokerUrl);
            ConnectionFactory connectionFactory = ConnectionFactoryContainer.getConsumerConnectionFactory(brokerUrl);
            if (this.listenerContainerMap.containsKey(connectionFactory)) {
                continue;
            }

            DefaultMessageListenerContainer defaultMessageListenerContainer = new DefaultMessageListenerContainer();

            defaultMessageListenerContainer.setCacheLevel(this.consumerConfig.getCacheLevel());
            defaultMessageListenerContainer.setConcurrentConsumers(this.consumerConfig.getConcurrentConsumers());
            ActiveMQQueue activeMQQueue = new ActiveMQQueue();
            activeMQQueue.setPhysicalName(this.consumerConfig.getQueueName());
            if(this.consumerConfig.getAcknowledgemode() < 0 || this.consumerConfig.getAcknowledgemode() > 4) {
                this.consumerConfig.setAcknowledgemode( Session.AUTO_ACKNOWLEDGE);
            }

            if(this.consumerConfig.getAcknowledgemode() == Session.SESSION_TRANSACTED) {
                defaultMessageListenerContainer.setSessionTransacted(true);
            }

            defaultMessageListenerContainer.setSessionAcknowledgeMode(this.consumerConfig.getAcknowledgemode());

            defaultMessageListenerContainer.setConnectionFactory(connectionFactory);
            defaultMessageListenerContainer.setDestination(activeMQQueue);
            defaultMessageListenerContainer.setMessageListener(this);
            defaultMessageListenerContainer.initialize();
            defaultMessageListenerContainer.start();
            this.listenerContainerMap.put(connectionFactory, defaultMessageListenerContainer);

        }
    }
}
 
Example 3
Source File: SolaceController.java    From solace-samples-cloudfoundry-java with Apache License 2.0 5 votes vote down vote up
public DefaultMessageListenerContainer createListener(String destination) {
    // do something here to create a message listener container
    DefaultMessageListenerContainer lc = new DefaultMessageListenerContainer();
    lc.setConnectionFactory(connectionFactory);
    lc.setDestinationName(destination);
    lc.setMessageListener(new SimpleMessageListener());
    lc.setPubSubDomain(true);
    lc.initialize();
    return lc;
}
 
Example 4
Source File: SolaceController.java    From solace-samples-cloudfoundry-java with Apache License 2.0 5 votes vote down vote up
public DefaultMessageListenerContainer createListener(String destination) {
    // do something here to create a message listener container
    DefaultMessageListenerContainer lc = new DefaultMessageListenerContainer();
    lc.setConnectionFactory((ConnectionFactory) connectionFactory.getObject());
    lc.setDestinationResolver(jndiDestinationResolver);
    lc.setDestinationName(destination);
    lc.setMessageListener(new SimpleMessageListener());
    lc.setPubSubDomain(true);
    lc.initialize();
    return lc;
}