Search in sources :

Example 11 with MessageListener

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

the class JmsListenerContainerFactoryTests method createJcaContainerFullConfig.

@Test
public void createJcaContainerFullConfig() {
    DefaultJcaListenerContainerFactory factory = new DefaultJcaListenerContainerFactory();
    setDefaultJcaConfig(factory);
    factory.setConcurrency("10");
    SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
    MessageListener messageListener = new MessageListenerAdapter();
    endpoint.setMessageListener(messageListener);
    endpoint.setDestination("myQueue");
    JmsMessageEndpointManager container = factory.createListenerContainer(endpoint);
    assertDefaultJcaConfig(container);
    assertThat(container.getActivationSpecConfig().getMaxConcurrency()).isEqualTo(10);
    assertThat(container.getMessageListener()).isEqualTo(messageListener);
    assertThat(container.getActivationSpecConfig().getDestinationName()).isEqualTo("myQueue");
}
Also used : MessageListenerAdapter(org.springframework.jms.listener.adapter.MessageListenerAdapter) JmsMessageEndpointManager(org.springframework.jms.listener.endpoint.JmsMessageEndpointManager) MessageListener(jakarta.jms.MessageListener) Test(org.junit.jupiter.api.Test)

Example 12 with MessageListener

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

the class JmsListenerContainerFactoryTests method createSimpleContainer.

@Test
public void createSimpleContainer() {
    SimpleJmsListenerContainerFactory factory = new SimpleJmsListenerContainerFactory();
    setDefaultJmsConfig(factory);
    SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
    MessageListener messageListener = new MessageListenerAdapter();
    endpoint.setMessageListener(messageListener);
    endpoint.setDestination("myQueue");
    SimpleMessageListenerContainer container = factory.createListenerContainer(endpoint);
    assertDefaultJmsConfig(container);
    assertThat(container.getMessageListener()).isEqualTo(messageListener);
    assertThat(container.getDestinationName()).isEqualTo("myQueue");
}
Also used : MessageListenerAdapter(org.springframework.jms.listener.adapter.MessageListenerAdapter) MessageListener(jakarta.jms.MessageListener) SimpleMessageListenerContainer(org.springframework.jms.listener.SimpleMessageListenerContainer) Test(org.junit.jupiter.api.Test)

Example 13 with MessageListener

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

the class JmsNamespaceHandlerTests method testListeners.

@Test
public void testListeners() throws Exception {
    TestBean testBean1 = context.getBean("testBean1", TestBean.class);
    TestBean testBean2 = context.getBean("testBean2", TestBean.class);
    TestMessageListener testBean3 = context.getBean("testBean3", TestMessageListener.class);
    assertThat(testBean1.getName()).isNull();
    assertThat(testBean2.getName()).isNull();
    assertThat(testBean3.message).isNull();
    TextMessage message1 = mock(TextMessage.class);
    given(message1.getText()).willReturn("Test1");
    MessageListener listener1 = getListener("listener1");
    listener1.onMessage(message1);
    assertThat(testBean1.getName()).isEqualTo("Test1");
    TextMessage message2 = mock(TextMessage.class);
    given(message2.getText()).willReturn("Test2");
    MessageListener listener2 = getListener("listener2");
    listener2.onMessage(message2);
    assertThat(testBean2.getName()).isEqualTo("Test2");
    TextMessage message3 = mock(TextMessage.class);
    MessageListener listener3 = getListener(DefaultMessageListenerContainer.class.getName() + "#0");
    listener3.onMessage(message3);
    assertThat(testBean3.message).isSameAs(message3);
}
Also used : TestBean(org.springframework.beans.testfixture.beans.TestBean) MessageListener(jakarta.jms.MessageListener) TextMessage(jakarta.jms.TextMessage) Test(org.junit.jupiter.api.Test)

Example 14 with MessageListener

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

the class SimpleJmsListenerEndpoint method createMessageListener.

@Override
protected MessageListener createMessageListener(MessageListenerContainer container) {
    MessageListener listener = getMessageListener();
    Assert.state(listener != null, "No MessageListener set");
    return listener;
}
Also used : MessageListener(jakarta.jms.MessageListener)

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