Example usage for org.springframework.jms.listener DefaultMessageListenerContainer CACHE_CONNECTION

List of usage examples for org.springframework.jms.listener DefaultMessageListenerContainer CACHE_CONNECTION

Introduction

In this page you can find the example usage for org.springframework.jms.listener DefaultMessageListenerContainer CACHE_CONNECTION.

Prototype

int CACHE_CONNECTION

To view the source code for org.springframework.jms.listener DefaultMessageListenerContainer CACHE_CONNECTION.

Click Source Link

Document

Constant that indicates to cache a shared JMS Connection for each listener thread.

Usage

From source file:org.apache.servicemix.jms.JmsConsumerEndpointTest.java

public void testDurableConsumerDefault() throws Exception {
    JmsComponent component = new JmsComponent();
    JmsConsumerEndpoint endpoint = new JmsConsumerEndpoint();
    endpoint.setService(new QName("jms"));
    endpoint.setEndpoint("endpoint");
    endpoint.setTargetService(new QName("receiver"));
    endpoint.setListenerType("default");
    endpoint.setConnectionFactory(connectionFactory);
    endpoint.setPubSubDomain(true);/*from ww  w  .j a v  a2s.  c  om*/
    endpoint.setSubscriptionDurable(true);
    endpoint.setClientId("clientId");
    endpoint.setDestinationName("destinationTopic");
    endpoint.setCacheLevel(DefaultMessageListenerContainer.CACHE_CONNECTION);
    component.setEndpoints(new JmsConsumerEndpoint[] { endpoint });
    container.activateComponent(component, "servicemix-jms");
    Thread.sleep(500);
    container.start();

    JmsTemplate jmsTemplate = new JmsTemplate();
    jmsTemplate.setConnectionFactory(new PooledConnectionFactory(connectionFactory));
    jmsTemplate.setPubSubDomain(true);
    jmsTemplate.afterPropertiesSet();
    jmsTemplate.convertAndSend("destinationTopic", "<hello>world</hello>");
    receiver.getMessageList().assertMessagesReceived(1);
    Thread.sleep(500);
}

From source file:org.apache.camel.component.jms.JmsConfiguration.java

/**
 * Defaults the JMS cache level if none is explicitly specified. Note that
 * due to this <a//w  w  w.  j a v  a 2  s .co m
 * href="http://opensource.atlassian.com/projects/spring/browse/SPR-3890">Spring
 * Bug</a> we cannot use CACHE_CONSUMER by default (which we should do as
 * its most efficient) unless the spring version is 2.5.1 or later. Instead
 * we use CACHE_CONNECTION - part from for non-durable topics which must use
 * CACHE_CONSUMER to avoid missing messages (due to the consumer being
 * created and destroyed per message).
 *
 * @param endpoint the endpoint
 * @return the cache level
 */
protected int defaultCacheLevel(JmsEndpoint endpoint) {
    // if we are on a new enough spring version we can assume CACHE_CONSUMER
    if (PackageHelper.isValidVersion("org.springframework.jms", 2.51D)) {
        return DefaultMessageListenerContainer.CACHE_CONSUMER;
    } else {
        if (endpoint.isPubSubDomain() && !isSubscriptionDurable()) {
            // we must cache the consumer or we will miss messages
            // see https://issues.apache.org/activemq/browse/CAMEL-253
            return DefaultMessageListenerContainer.CACHE_CONSUMER;
        } else {
            // to enable consuming and sending with a single JMS session (to
            // avoid XA) we can only use CACHE_CONNECTION
            // due to this bug :
            // http://opensource.atlassian.com/projects/spring/browse/SPR-3890
            return DefaultMessageListenerContainer.CACHE_CONNECTION;
        }
    }
}