Search in sources :

Example 1 with MessageListener

use of jakarta.jms.MessageListener 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(jakarta.jms.MessageListener) Session(jakarta.jms.Session)

Example 2 with MessageListener

use of jakarta.jms.MessageListener in project spring-framework by spring-projects.

the class JmsListenerContainerFactoryTests method endpointConcurrencyTakesPrecedence.

@Test
public void endpointConcurrencyTakesPrecedence() {
    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
    factory.setConcurrency("2-10");
    SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
    MessageListener messageListener = new MessageListenerAdapter();
    endpoint.setMessageListener(messageListener);
    endpoint.setDestination("myQueue");
    endpoint.setConcurrency("4-6");
    DefaultMessageListenerContainer container = factory.createListenerContainer(endpoint);
    assertThat(container.getConcurrentConsumers()).isEqualTo(4);
    assertThat(container.getMaxConcurrentConsumers()).isEqualTo(6);
}
Also used : MessageListenerAdapter(org.springframework.jms.listener.adapter.MessageListenerAdapter) DefaultMessageListenerContainer(org.springframework.jms.listener.DefaultMessageListenerContainer) MessageListener(jakarta.jms.MessageListener) Test(org.junit.jupiter.api.Test)

Example 3 with MessageListener

use of jakarta.jms.MessageListener 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);
    assertThat(container.getCacheLevel()).isEqualTo(DefaultMessageListenerContainer.CACHE_CONSUMER);
    assertThat(container.getConcurrentConsumers()).isEqualTo(3);
    assertThat(container.getMaxConcurrentConsumers()).isEqualTo(10);
    assertThat(container.getMaxMessagesPerTask()).isEqualTo(5);
    assertThat(container.getMessageListener()).isEqualTo(messageListener);
    assertThat(container.getDestinationName()).isEqualTo("myQueue");
}
Also used : MessageListenerAdapter(org.springframework.jms.listener.adapter.MessageListenerAdapter) DefaultMessageListenerContainer(org.springframework.jms.listener.DefaultMessageListenerContainer) MessageListener(jakarta.jms.MessageListener) Test(org.junit.jupiter.api.Test)

Example 4 with MessageListener

use of jakarta.jms.MessageListener 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);
    assertThat(container.getDestinationName()).isEqualTo("myQueue");
    assertThat(container.getMessageSelector()).isEqualTo("foo = 'bar'");
    assertThat(container.getSubscriptionName()).isEqualTo("mySubscription");
    assertThat(container.getConcurrentConsumers()).isEqualTo(5);
    assertThat(container.getMaxConcurrentConsumers()).isEqualTo(10);
    assertThat(container.getMessageListener()).isEqualTo(messageListener);
}
Also used : DefaultMessageListenerContainer(org.springframework.jms.listener.DefaultMessageListenerContainer) MessageListenerAdapter(org.springframework.jms.listener.adapter.MessageListenerAdapter) MessageListener(jakarta.jms.MessageListener) Test(org.junit.jupiter.api.Test)

Example 5 with MessageListener

use of jakarta.jms.MessageListener in project spring-framework by spring-projects.

the class JmsListenerEndpointTests method setupJcaMessageContainerFullConfig.

@Test
public void setupJcaMessageContainerFullConfig() {
    JmsMessageEndpointManager container = new JmsMessageEndpointManager();
    MessageListener messageListener = new MessageListenerAdapter();
    SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
    endpoint.setDestination("myQueue");
    endpoint.setSelector("foo = 'bar'");
    endpoint.setSubscription("mySubscription");
    endpoint.setConcurrency("10");
    endpoint.setMessageListener(messageListener);
    endpoint.setupListenerContainer(container);
    JmsActivationSpecConfig config = container.getActivationSpecConfig();
    assertThat(config.getDestinationName()).isEqualTo("myQueue");
    assertThat(config.getMessageSelector()).isEqualTo("foo = 'bar'");
    assertThat(config.getSubscriptionName()).isEqualTo("mySubscription");
    assertThat(config.getMaxConcurrency()).isEqualTo(10);
    assertThat(container.getMessageListener()).isEqualTo(messageListener);
}
Also used : MessageListenerAdapter(org.springframework.jms.listener.adapter.MessageListenerAdapter) JmsMessageEndpointManager(org.springframework.jms.listener.endpoint.JmsMessageEndpointManager) MessageListener(jakarta.jms.MessageListener) JmsActivationSpecConfig(org.springframework.jms.listener.endpoint.JmsActivationSpecConfig) Test(org.junit.jupiter.api.Test)

Aggregations

MessageListener (jakarta.jms.MessageListener)14 Test (org.junit.jupiter.api.Test)12 MessageListenerAdapter (org.springframework.jms.listener.adapter.MessageListenerAdapter)9 DefaultMessageListenerContainer (org.springframework.jms.listener.DefaultMessageListenerContainer)5 Session (jakarta.jms.Session)3 Connection (jakarta.jms.Connection)2 ConnectionFactory (jakarta.jms.ConnectionFactory)2 ExceptionListener (jakarta.jms.ExceptionListener)2 JMSException (jakarta.jms.JMSException)2 Message (jakarta.jms.Message)2 MessageConsumer (jakarta.jms.MessageConsumer)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.assertThatIllegalArgumentException (org.assertj.core.api.Assertions.assertThatIllegalArgumentException)2 Assertions.fail (org.assertj.core.api.Assertions.fail)2 BDDMockito.given (org.mockito.BDDMockito.given)2 Mockito.mock (org.mockito.Mockito.mock)2 Mockito.verify (org.mockito.Mockito.verify)2 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)2