Search in sources :

Example 1 with JmsMessageEndpointManager

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

the class DefaultJcaListenerContainerFactory method createListenerContainer.

@Override
public JmsMessageEndpointManager createListenerContainer(JmsListenerEndpoint endpoint) {
    if (this.destinationResolver != null && this.activationSpecFactory != null) {
        throw new IllegalStateException("Specify either 'activationSpecFactory' or " + "'destinationResolver', not both. If you define a dedicated JmsActivationSpecFactory bean, " + "specify the custom DestinationResolver there (if possible)");
    }
    JmsMessageEndpointManager instance = createContainerInstance();
    if (this.resourceAdapter != null) {
        instance.setResourceAdapter(this.resourceAdapter);
    }
    if (this.activationSpecFactory != null) {
        instance.setActivationSpecFactory(this.activationSpecFactory);
    }
    if (this.destinationResolver != null) {
        instance.setDestinationResolver(this.destinationResolver);
    }
    if (this.transactionManager != null) {
        instance.setTransactionManager(this.transactionManager);
    }
    if (this.phase != null) {
        instance.setPhase(this.phase);
    }
    instance.setActivationSpecConfig(this);
    endpoint.setupListenerContainer(instance);
    return instance;
}
Also used : JmsMessageEndpointManager(org.springframework.jms.listener.endpoint.JmsMessageEndpointManager)

Example 2 with JmsMessageEndpointManager

use of org.springframework.jms.listener.endpoint.JmsMessageEndpointManager 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();
    assertEquals("myQueue", config.getDestinationName());
    assertEquals("foo = 'bar'", config.getMessageSelector());
    assertEquals("mySubscription", config.getSubscriptionName());
    assertEquals(10, config.getMaxConcurrency());
    assertEquals(messageListener, container.getMessageListener());
}
Also used : MessageListenerAdapter(org.springframework.jms.listener.adapter.MessageListenerAdapter) JmsMessageEndpointManager(org.springframework.jms.listener.endpoint.JmsMessageEndpointManager) MessageListener(javax.jms.MessageListener) JmsActivationSpecConfig(org.springframework.jms.listener.endpoint.JmsActivationSpecConfig) Test(org.junit.Test)

Example 3 with JmsMessageEndpointManager

use of org.springframework.jms.listener.endpoint.JmsMessageEndpointManager 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);
    assertEquals(10, container.getActivationSpecConfig().getMaxConcurrency());
    assertEquals(messageListener, container.getMessageListener());
    assertEquals("myQueue", container.getActivationSpecConfig().getDestinationName());
}
Also used : MessageListenerAdapter(org.springframework.jms.listener.adapter.MessageListenerAdapter) JmsMessageEndpointManager(org.springframework.jms.listener.endpoint.JmsMessageEndpointManager) MessageListener(javax.jms.MessageListener) Test(org.junit.Test)

Example 4 with JmsMessageEndpointManager

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

the class JmsNamespaceHandlerTests method testJcaContainerConfiguration.

@Test
public void testJcaContainerConfiguration() throws Exception {
    Map<String, JmsMessageEndpointManager> containers = context.getBeansOfType(JmsMessageEndpointManager.class);
    assertTrue("listener3 not found", containers.containsKey("listener3"));
    JmsMessageEndpointManager listener3 = containers.get("listener3");
    assertEquals("Wrong resource adapter", context.getBean("testResourceAdapter"), listener3.getResourceAdapter());
    assertEquals("Wrong activation spec factory", context.getBean("testActivationSpecFactory"), new DirectFieldAccessor(listener3).getPropertyValue("activationSpecFactory"));
    Object endpointFactory = new DirectFieldAccessor(listener3).getPropertyValue("endpointFactory");
    Object messageListener = new DirectFieldAccessor(endpointFactory).getPropertyValue("messageListener");
    assertEquals("Wrong message listener", MessageListenerAdapter.class, messageListener.getClass());
    MessageListenerAdapter adapter = (MessageListenerAdapter) messageListener;
    DirectFieldAccessor adapterFieldAccessor = new DirectFieldAccessor(adapter);
    assertEquals("Message converter not set properly", context.getBean("testMessageConverter"), adapterFieldAccessor.getPropertyValue("messageConverter"));
    assertEquals("Wrong delegate", context.getBean("testBean1"), adapterFieldAccessor.getPropertyValue("delegate"));
    assertEquals("Wrong method name", "setName", adapterFieldAccessor.getPropertyValue("defaultListenerMethod"));
}
Also used : MessageListenerAdapter(org.springframework.jms.listener.adapter.MessageListenerAdapter) JmsMessageEndpointManager(org.springframework.jms.listener.endpoint.JmsMessageEndpointManager) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Example 5 with JmsMessageEndpointManager

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

the class JmsNamespaceHandlerTests method testJcaContainerFactoryConfiguration.

@Test
public void testJcaContainerFactoryConfiguration() {
    Map<String, DefaultJcaListenerContainerFactory> containers = context.getBeansOfType(DefaultJcaListenerContainerFactory.class);
    DefaultJcaListenerContainerFactory factory = containers.get("testJcaFactory");
    assertNotNull("No factory registered with testJcaFactory id", factory);
    JmsMessageEndpointManager container = factory.createListenerContainer(createDummyEndpoint());
    assertEquals("explicit resource adapter not set", context.getBean("testResourceAdapter"), container.getResourceAdapter());
    assertEquals("explicit message converter not set", context.getBean("testMessageConverter"), container.getActivationSpecConfig().getMessageConverter());
    assertEquals("Wrong pub/sub", true, container.isPubSubDomain());
    assertEquals("wrong concurrency", 5, container.getActivationSpecConfig().getMaxConcurrency());
    assertEquals("Wrong prefetch", 50, container.getActivationSpecConfig().getPrefetchSize());
    assertEquals("Wrong phase", 77, container.getPhase());
}
Also used : JmsMessageEndpointManager(org.springframework.jms.listener.endpoint.JmsMessageEndpointManager) Test(org.junit.Test)

Aggregations

JmsMessageEndpointManager (org.springframework.jms.listener.endpoint.JmsMessageEndpointManager)7 Test (org.junit.Test)6 MessageListenerAdapter (org.springframework.jms.listener.adapter.MessageListenerAdapter)3 MessageListener (javax.jms.MessageListener)2 DefaultMessageListenerContainer (org.springframework.jms.listener.DefaultMessageListenerContainer)2 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 JmsActivationSpecConfig (org.springframework.jms.listener.endpoint.JmsActivationSpecConfig)1