Search in sources :

Example 1 with DefaultMessageListenerContainer

use of org.springframework.jms.listener.DefaultMessageListenerContainer in project camel by apache.

the class JmsConfiguration method configureMessageListenerContainer.

protected void configureMessageListenerContainer(AbstractMessageListenerContainer container, JmsEndpoint endpoint) throws Exception {
    container.setConnectionFactory(getListenerConnectionFactory());
    if (endpoint instanceof DestinationEndpoint) {
        container.setDestinationResolver(createDestinationResolver((DestinationEndpoint) endpoint));
    } else if (destinationResolver != null) {
        container.setDestinationResolver(destinationResolver);
    }
    container.setAutoStartup(autoStartup);
    if (durableSubscriptionName != null) {
        container.setDurableSubscriptionName(durableSubscriptionName);
        container.setSubscriptionDurable(true);
    }
    if (clientId != null) {
        container.setClientId(clientId);
    }
    if (exceptionListener != null) {
        container.setExceptionListener(exceptionListener);
    }
    if (errorHandler != null) {
        container.setErrorHandler(errorHandler);
    } else {
        ErrorHandler handler = new DefaultSpringErrorHandler(endpoint.getCamelContext(), EndpointMessageListener.class, getErrorHandlerLoggingLevel(), isErrorHandlerLogStackTrace());
        container.setErrorHandler(handler);
    }
    container.setAcceptMessagesWhileStopping(acceptMessagesWhileStopping);
    container.setExposeListenerSession(exposeListenerSession);
    container.setSessionTransacted(transacted);
    if (transacted) {
        container.setSessionAcknowledgeMode(Session.SESSION_TRANSACTED);
    } else {
        if (acknowledgementMode >= 0) {
            container.setSessionAcknowledgeMode(acknowledgementMode);
        } else if (acknowledgementModeName != null) {
            container.setSessionAcknowledgeModeName(acknowledgementModeName);
        }
    }
    if (endpoint.getSelector() != null && endpoint.getSelector().length() != 0) {
        container.setMessageSelector(endpoint.getSelector());
    }
    if (container instanceof DefaultMessageListenerContainer) {
        DefaultMessageListenerContainer listenerContainer = (DefaultMessageListenerContainer) container;
        configureDefaultMessageListenerContainer(endpoint, listenerContainer);
    } else if (container instanceof SimpleMessageListenerContainer) {
        SimpleMessageListenerContainer listenerContainer = (SimpleMessageListenerContainer) container;
        configureSimpleMessageListenerContainer(listenerContainer);
    }
}
Also used : DefaultMessageListenerContainer(org.springframework.jms.listener.DefaultMessageListenerContainer) ErrorHandler(org.springframework.util.ErrorHandler) SimpleMessageListenerContainer(org.springframework.jms.listener.SimpleMessageListenerContainer)

Example 2 with DefaultMessageListenerContainer

use of org.springframework.jms.listener.DefaultMessageListenerContainer in project camel by apache.

the class JmsEndpointConfigurationTest method assertCacheLevel.

protected void assertCacheLevel(JmsEndpoint endpoint, int expected) throws Exception {
    JmsConsumer consumer = endpoint.createConsumer(dummyProcessor);
    AbstractMessageListenerContainer container = consumer.getListenerContainer();
    DefaultMessageListenerContainer defaultContainer = assertIsInstanceOf(DefaultMessageListenerContainer.class, container);
    int cacheLevel = defaultContainer.getCacheLevel();
    assertEquals("CacheLevel", expected, cacheLevel);
}
Also used : DefaultMessageListenerContainer(org.springframework.jms.listener.DefaultMessageListenerContainer) AbstractMessageListenerContainer(org.springframework.jms.listener.AbstractMessageListenerContainer)

Example 3 with DefaultMessageListenerContainer

use of org.springframework.jms.listener.DefaultMessageListenerContainer in project spring-framework by spring-projects.

the class JmsListenerContainerFactoryIntegrationTests method invokeListener.

@SuppressWarnings("unchecked")
private void invokeListener(JmsListenerEndpoint endpoint, Message message) throws JMSException {
    DefaultMessageListenerContainer messageListenerContainer = containerFactory.createListenerContainer(endpoint);
    Object listener = messageListenerContainer.getMessageListener();
    if (listener instanceof SessionAwareMessageListener) {
        ((SessionAwareMessageListener<Message>) listener).onMessage(message, mock(Session.class));
    } else {
        ((MessageListener) listener).onMessage(message);
    }
}
Also used : DefaultMessageListenerContainer(org.springframework.jms.listener.DefaultMessageListenerContainer) SessionAwareMessageListener(org.springframework.jms.listener.SessionAwareMessageListener) SessionAwareMessageListener(org.springframework.jms.listener.SessionAwareMessageListener) MessageListener(javax.jms.MessageListener) Session(javax.jms.Session)

Example 4 with DefaultMessageListenerContainer

use of org.springframework.jms.listener.DefaultMessageListenerContainer in project spring-framework by spring-projects.

the class JmsListenerContainerFactoryTests method createJmsContainerFullConfig.

@Test
public void createJmsContainerFullConfig() {
    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
    setDefaultJmsConfig(factory);
    factory.setCacheLevel(DefaultMessageListenerContainer.CACHE_CONSUMER);
    factory.setConcurrency("3-10");
    factory.setMaxMessagesPerTask(5);
    SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
    MessageListener messageListener = new MessageListenerAdapter();
    endpoint.setMessageListener(messageListener);
    endpoint.setDestination("myQueue");
    DefaultMessageListenerContainer container = factory.createListenerContainer(endpoint);
    assertDefaultJmsConfig(container);
    assertEquals(DefaultMessageListenerContainer.CACHE_CONSUMER, container.getCacheLevel());
    assertEquals(3, container.getConcurrentConsumers());
    assertEquals(10, container.getMaxConcurrentConsumers());
    assertEquals(5, container.getMaxMessagesPerTask());
    assertEquals(messageListener, container.getMessageListener());
    assertEquals("myQueue", container.getDestinationName());
}
Also used : MessageListenerAdapter(org.springframework.jms.listener.adapter.MessageListenerAdapter) DefaultMessageListenerContainer(org.springframework.jms.listener.DefaultMessageListenerContainer) MessageListener(javax.jms.MessageListener) Test(org.junit.Test)

Example 5 with DefaultMessageListenerContainer

use of org.springframework.jms.listener.DefaultMessageListenerContainer in project spring-framework by spring-projects.

the class JmsListenerEndpointTests method setupJmsMessageContainerFullConfig.

@Test
public void setupJmsMessageContainerFullConfig() {
    DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
    MessageListener messageListener = new MessageListenerAdapter();
    SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
    endpoint.setDestination("myQueue");
    endpoint.setSelector("foo = 'bar'");
    endpoint.setSubscription("mySubscription");
    endpoint.setConcurrency("5-10");
    endpoint.setMessageListener(messageListener);
    endpoint.setupListenerContainer(container);
    assertEquals("myQueue", container.getDestinationName());
    assertEquals("foo = 'bar'", container.getMessageSelector());
    assertEquals("mySubscription", container.getSubscriptionName());
    assertEquals(5, container.getConcurrentConsumers());
    assertEquals(10, container.getMaxConcurrentConsumers());
    assertEquals(messageListener, container.getMessageListener());
}
Also used : DefaultMessageListenerContainer(org.springframework.jms.listener.DefaultMessageListenerContainer) MessageListenerAdapter(org.springframework.jms.listener.adapter.MessageListenerAdapter) MessageListener(javax.jms.MessageListener) Test(org.junit.Test)

Aggregations

DefaultMessageListenerContainer (org.springframework.jms.listener.DefaultMessageListenerContainer)24 Test (org.junit.Test)15 DefaultJmsListenerContainerFactory (org.springframework.jms.config.DefaultJmsListenerContainerFactory)7 JmsListenerEndpoint (org.springframework.jms.config.JmsListenerEndpoint)7 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)5 MessageListener (javax.jms.MessageListener)4 Bean (org.springframework.context.annotation.Bean)4 MessageListenerAdapter (org.springframework.jms.listener.adapter.MessageListenerAdapter)3 DefaultSpringErrorHandler (org.apache.camel.component.jms.DefaultSpringErrorHandler)2 CollectionJobListener (org.opennms.nrtg.nrtcollector.internal.jms.CollectionJobListener)2 JmsMessageEndpointManager (org.springframework.jms.listener.endpoint.JmsMessageEndpointManager)2 ErrorHandler (org.springframework.util.ErrorHandler)2 BigInteger (java.math.BigInteger)1 Random (java.util.Random)1 ConnectionFactory (javax.jms.ConnectionFactory)1 Session (javax.jms.Session)1 DefaultJmsMessageListenerContainer (org.apache.camel.component.jms.DefaultJmsMessageListenerContainer)1 ReplyToType (org.apache.camel.component.jms.ReplyToType)1 JmsTemplate (org.springframework.jms.core.JmsTemplate)1 AbstractMessageListenerContainer (org.springframework.jms.listener.AbstractMessageListenerContainer)1