Search in sources :

Example 16 with DefaultMessageListenerContainer

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

the class JmsAutoConfigurationTests method testDefaultContainerFactoryWithJtaTransactionManager.

@Test
public void testDefaultContainerFactoryWithJtaTransactionManager() {
    this.context = createContext(TestConfiguration7.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()).isFalse();
    assertThat(new DirectFieldAccessor(listenerContainer).getPropertyValue("transactionManager")).isSameAs(this.context.getBean(JtaTransactionManager.class));
}
Also used : DefaultMessageListenerContainer(org.springframework.jms.listener.DefaultMessageListenerContainer) JmsListenerEndpoint(org.springframework.jms.config.JmsListenerEndpoint) DefaultJmsListenerContainerFactory(org.springframework.jms.config.DefaultJmsListenerContainerFactory) JtaTransactionManager(org.springframework.transaction.jta.JtaTransactionManager) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Example 17 with DefaultMessageListenerContainer

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

the class JmsAutoConfigurationTests method testDefaultContainerFactoryNoTransactionManager.

@Test
public void testDefaultContainerFactoryNoTransactionManager() {
    this.context = createContext(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 18 with DefaultMessageListenerContainer

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

the class JmsListenerContainerFactoryTests method backOffOverridesRecoveryInterval.

@Test
public void backOffOverridesRecoveryInterval() {
    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
    BackOff backOff = new FixedBackOff();
    factory.setBackOff(backOff);
    factory.setRecoveryInterval(2000L);
    SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
    MessageListener messageListener = new MessageListenerAdapter();
    endpoint.setMessageListener(messageListener);
    endpoint.setDestination("myQueue");
    DefaultMessageListenerContainer container = factory.createListenerContainer(endpoint);
    assertSame(backOff, new DirectFieldAccessor(container).getPropertyValue("backOff"));
}
Also used : MessageListenerAdapter(org.springframework.jms.listener.adapter.MessageListenerAdapter) DefaultMessageListenerContainer(org.springframework.jms.listener.DefaultMessageListenerContainer) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) MessageListener(javax.jms.MessageListener) FixedBackOff(org.springframework.util.backoff.FixedBackOff) BackOff(org.springframework.util.backoff.BackOff) FixedBackOff(org.springframework.util.backoff.FixedBackOff) Test(org.junit.Test)

Example 19 with DefaultMessageListenerContainer

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

the class JmsListenerEndpointTests method setupMessageContainerNoListener.

@Test
public void setupMessageContainerNoListener() {
    DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
    SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
    thrown.expect(IllegalStateException.class);
    endpoint.setupListenerContainer(container);
}
Also used : DefaultMessageListenerContainer(org.springframework.jms.listener.DefaultMessageListenerContainer) Test(org.junit.Test)

Example 20 with DefaultMessageListenerContainer

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

the class JmsNamespaceHandlerTests method testConcurrency.

@Test
public void testConcurrency() {
    // JMS
    DefaultMessageListenerContainer listener0 = this.context.getBean(DefaultMessageListenerContainer.class.getName() + "#0", DefaultMessageListenerContainer.class);
    DefaultMessageListenerContainer listener1 = this.context.getBean("listener1", DefaultMessageListenerContainer.class);
    DefaultMessageListenerContainer listener2 = this.context.getBean("listener2", DefaultMessageListenerContainer.class);
    assertEquals("Wrong concurrency on listener using placeholder", 2, listener0.getConcurrentConsumers());
    assertEquals("Wrong concurrency on listener using placeholder", 3, listener0.getMaxConcurrentConsumers());
    assertEquals("Wrong concurrency on listener1", 3, listener1.getConcurrentConsumers());
    assertEquals("Wrong max concurrency on listener1", 5, listener1.getMaxConcurrentConsumers());
    assertEquals("Wrong custom concurrency on listener2", 5, listener2.getConcurrentConsumers());
    assertEquals("Wrong custom max concurrency on listener2", 10, listener2.getMaxConcurrentConsumers());
    // JCA
    JmsMessageEndpointManager listener3 = this.context.getBean("listener3", JmsMessageEndpointManager.class);
    JmsMessageEndpointManager listener4 = this.context.getBean("listener4", JmsMessageEndpointManager.class);
    assertEquals("Wrong concurrency on listener3", 5, listener3.getActivationSpecConfig().getMaxConcurrency());
    assertEquals("Wrong custom concurrency on listener4", 7, listener4.getActivationSpecConfig().getMaxConcurrency());
}
Also used : DefaultMessageListenerContainer(org.springframework.jms.listener.DefaultMessageListenerContainer) JmsMessageEndpointManager(org.springframework.jms.listener.endpoint.JmsMessageEndpointManager) 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