Search in sources :

Example 6 with DefaultMessageListenerContainer

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

the class JmsNamespaceHandlerTests method testJmsContainerFactoryConfiguration.

@Test
public void testJmsContainerFactoryConfiguration() {
    Map<String, DefaultJmsListenerContainerFactory> containers = context.getBeansOfType(DefaultJmsListenerContainerFactory.class);
    DefaultJmsListenerContainerFactory factory = containers.get("testJmsFactory");
    assertNotNull("No factory registered with testJmsFactory id", factory);
    DefaultMessageListenerContainer container = factory.createListenerContainer(createDummyEndpoint());
    assertEquals("explicit connection factory not set", context.getBean(EXPLICIT_CONNECTION_FACTORY), container.getConnectionFactory());
    assertEquals("explicit destination resolver not set", context.getBean("testDestinationResolver"), container.getDestinationResolver());
    assertEquals("explicit message converter not set", context.getBean("testMessageConverter"), container.getMessageConverter());
    assertEquals("Wrong pub/sub", true, container.isPubSubDomain());
    assertEquals("Wrong durable flag", true, container.isSubscriptionDurable());
    assertEquals("wrong cache", DefaultMessageListenerContainer.CACHE_CONNECTION, container.getCacheLevel());
    assertEquals("wrong concurrency", 3, container.getConcurrentConsumers());
    assertEquals("wrong concurrency", 5, container.getMaxConcurrentConsumers());
    assertEquals("wrong prefetch", 50, container.getMaxMessagesPerTask());
    assertEquals("Wrong phase", 99, container.getPhase());
    assertSame(context.getBean("testBackOff"), new DirectFieldAccessor(container).getPropertyValue("backOff"));
}
Also used : DefaultMessageListenerContainer(org.springframework.jms.listener.DefaultMessageListenerContainer) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Example 7 with DefaultMessageListenerContainer

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

the class JmsAutoConfigurationTests method testPubSubDomainActive.

@Test
public void testPubSubDomainActive() {
    load(TestConfiguration.class, "spring.jms.pubSubDomain:true");
    JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
    DefaultMessageListenerContainer defaultMessageListenerContainer = this.context.getBean(DefaultJmsListenerContainerFactory.class).createListenerContainer(mock(JmsListenerEndpoint.class));
    assertThat(jmsTemplate.isPubSubDomain()).isTrue();
    assertThat(defaultMessageListenerContainer.isPubSubDomain()).isTrue();
}
Also used : DefaultMessageListenerContainer(org.springframework.jms.listener.DefaultMessageListenerContainer) JmsListenerEndpoint(org.springframework.jms.config.JmsListenerEndpoint) DefaultJmsListenerContainerFactory(org.springframework.jms.config.DefaultJmsListenerContainerFactory) JmsTemplate(org.springframework.jms.core.JmsTemplate) Test(org.junit.Test)

Example 8 with DefaultMessageListenerContainer

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

the class JmsAutoConfigurationTests method testDefaultContainerFactoryNonJtaTransactionManager.

@Test
public void testDefaultContainerFactoryNonJtaTransactionManager() {
    this.context = createContext(TestConfiguration8.class, EnableJmsConfiguration.class);
    JmsListenerContainerFactory<?> jmsListenerContainerFactory = this.context.getBean("jmsListenerContainerFactory", JmsListenerContainerFactory.class);
    assertThat(jmsListenerContainerFactory.getClass()).isEqualTo(DefaultJmsListenerContainerFactory.class);
    DefaultMessageListenerContainer listenerContainer = ((DefaultJmsListenerContainerFactory) jmsListenerContainerFactory).createListenerContainer(mock(JmsListenerEndpoint.class));
    assertThat(listenerContainer.isSessionTransacted()).isTrue();
    assertThat(new DirectFieldAccessor(listenerContainer).getPropertyValue("transactionManager")).isNull();
}
Also used : DefaultMessageListenerContainer(org.springframework.jms.listener.DefaultMessageListenerContainer) JmsListenerEndpoint(org.springframework.jms.config.JmsListenerEndpoint) DefaultJmsListenerContainerFactory(org.springframework.jms.config.DefaultJmsListenerContainerFactory) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Example 9 with DefaultMessageListenerContainer

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

the class JmsAutoConfigurationTests method testCustomContainerFactoryWithConfigurer.

@Test
public void testCustomContainerFactoryWithConfigurer() {
    this.context = doLoad(new Class<?>[] { TestConfiguration9.class, EnableJmsConfiguration.class }, "spring.jms.listener.autoStartup=false");
    assertThat(this.context.containsBean("jmsListenerContainerFactory")).isTrue();
    JmsListenerContainerFactory<?> jmsListenerContainerFactory = this.context.getBean("customListenerContainerFactory", JmsListenerContainerFactory.class);
    assertThat(jmsListenerContainerFactory).isInstanceOf(DefaultJmsListenerContainerFactory.class);
    DefaultMessageListenerContainer listenerContainer = ((DefaultJmsListenerContainerFactory) jmsListenerContainerFactory).createListenerContainer(mock(JmsListenerEndpoint.class));
    assertThat(listenerContainer.getCacheLevel()).isEqualTo(DefaultMessageListenerContainer.CACHE_CONSUMER);
    assertThat(listenerContainer.isAutoStartup()).isFalse();
}
Also used : DefaultMessageListenerContainer(org.springframework.jms.listener.DefaultMessageListenerContainer) JmsListenerEndpoint(org.springframework.jms.config.JmsListenerEndpoint) DefaultJmsListenerContainerFactory(org.springframework.jms.config.DefaultJmsListenerContainerFactory) Test(org.junit.Test)

Example 10 with DefaultMessageListenerContainer

use of org.springframework.jms.listener.DefaultMessageListenerContainer in project Protocol-Adapter-IEC61850 by OSGP.

the class MessagingConfig method iec61850RequestsMessageListenerContainer.

@Bean
public DefaultMessageListenerContainer iec61850RequestsMessageListenerContainer(final JmsConfiguration iec61850RequestJmsConfiguration) {
    final DefaultMessageListenerContainer messageListenerContainer = iec61850RequestJmsConfiguration.getMessageListenerContainer();
    messageListenerContainer.setErrorHandler(new ErrorHandler() {

        @Override
        public void handleError(final Throwable t) {
            // Implementing ErrorHandler to prevent logging at WARN level
            // when JMSException is thrown: Execution of JMS message
            // listener failed, and no ErrorHandler has been set.
            LOGGER.debug("iec61850RequestsMessageListenerContainer.ErrorHandler.handleError()", t);
        }
    });
    return messageListenerContainer;
}
Also used : DefaultMessageListenerContainer(org.springframework.jms.listener.DefaultMessageListenerContainer) ErrorHandler(org.springframework.util.ErrorHandler) Bean(org.springframework.context.annotation.Bean)

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