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);
}
}
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);
}
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");
}
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);
}
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);
}
Aggregations