use of org.springframework.jms.config.MethodJmsListenerEndpoint in project spring-framework by spring-projects.
the class JmsListenerAnnotationBeanPostProcessor method processJmsListener.
/**
* Process the given {@link JmsListener} annotation on the given method,
* registering a corresponding endpoint for the given bean instance.
* @param jmsListener the annotation to process
* @param mostSpecificMethod the annotated method
* @param bean the instance to invoke the method on
* @see #createMethodJmsListenerEndpoint()
* @see JmsListenerEndpointRegistrar#registerEndpoint
*/
protected void processJmsListener(JmsListener jmsListener, Method mostSpecificMethod, Object bean) {
Method invocableMethod = AopUtils.selectInvocableMethod(mostSpecificMethod, bean.getClass());
MethodJmsListenerEndpoint endpoint = createMethodJmsListenerEndpoint();
endpoint.setBean(bean);
endpoint.setMethod(invocableMethod);
endpoint.setMostSpecificMethod(mostSpecificMethod);
endpoint.setMessageHandlerMethodFactory(this.messageHandlerMethodFactory);
endpoint.setEmbeddedValueResolver(this.embeddedValueResolver);
endpoint.setBeanFactory(this.beanFactory);
endpoint.setId(getEndpointId(jmsListener));
endpoint.setDestination(resolve(jmsListener.destination()));
if (StringUtils.hasText(jmsListener.selector())) {
endpoint.setSelector(resolve(jmsListener.selector()));
}
if (StringUtils.hasText(jmsListener.subscription())) {
endpoint.setSubscription(resolve(jmsListener.subscription()));
}
if (StringUtils.hasText(jmsListener.concurrency())) {
endpoint.setConcurrency(resolve(jmsListener.concurrency()));
}
JmsListenerContainerFactory<?> factory = null;
String containerFactoryBeanName = resolve(jmsListener.containerFactory());
if (StringUtils.hasText(containerFactoryBeanName)) {
Assert.state(this.beanFactory != null, "BeanFactory must be set to obtain container factory by bean name");
try {
factory = this.beanFactory.getBean(containerFactoryBeanName, JmsListenerContainerFactory.class);
} catch (NoSuchBeanDefinitionException ex) {
throw new BeanInitializationException("Could not register JMS listener endpoint on [" + mostSpecificMethod + "], no " + JmsListenerContainerFactory.class.getSimpleName() + " with id '" + containerFactoryBeanName + "' was found in the application context", ex);
}
}
this.registrar.registerEndpoint(endpoint, factory);
}
use of org.springframework.jms.config.MethodJmsListenerEndpoint in project spring-framework by spring-projects.
the class AbstractJmsAnnotationDrivenTests method testJmsListenerRepeatable.
/**
* Test for {@link JmsListenerRepeatableBean} and {@link JmsListenersBean} that validates that the
* {@code @JmsListener} annotation is repeatable and generate one specific container per annotation.
*/
public void testJmsListenerRepeatable(ApplicationContext context) {
JmsListenerContainerTestFactory simpleFactory = context.getBean("jmsListenerContainerFactory", JmsListenerContainerTestFactory.class);
assertEquals(2, simpleFactory.getListenerContainers().size());
MethodJmsListenerEndpoint first = (MethodJmsListenerEndpoint) simpleFactory.getListenerContainer("first").getEndpoint();
assertEquals("first", first.getId());
assertEquals("myQueue", first.getDestination());
assertEquals(null, first.getConcurrency());
MethodJmsListenerEndpoint second = (MethodJmsListenerEndpoint) simpleFactory.getListenerContainer("second").getEndpoint();
assertEquals("second", second.getId());
assertEquals("anotherQueue", second.getDestination());
assertEquals("2-10", second.getConcurrency());
}
use of org.springframework.jms.config.MethodJmsListenerEndpoint in project spring-framework by spring-projects.
the class JmsListenerAnnotationBeanPostProcessorTests method simpleMessageListener.
@Test
public void simpleMessageListener() throws Exception {
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.class, SimpleMessageListenerTestBean.class);
JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class);
assertEquals("One container should have been registered", 1, factory.getListenerContainers().size());
MessageListenerTestContainer container = factory.getListenerContainers().get(0);
JmsListenerEndpoint endpoint = container.getEndpoint();
assertEquals("Wrong endpoint type", MethodJmsListenerEndpoint.class, endpoint.getClass());
MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint) endpoint;
assertEquals(SimpleMessageListenerTestBean.class, methodEndpoint.getBean().getClass());
assertEquals(SimpleMessageListenerTestBean.class.getMethod("handleIt", String.class), methodEndpoint.getMethod());
assertEquals(SimpleMessageListenerTestBean.class.getMethod("handleIt", String.class), methodEndpoint.getMostSpecificMethod());
SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer();
methodEndpoint.setupListenerContainer(listenerContainer);
assertNotNull(listenerContainer.getMessageListener());
assertTrue("Should have been started " + container, container.isStarted());
// Close and stop the listeners
context.close();
assertTrue("Should have been stopped " + container, container.isStopped());
}
use of org.springframework.jms.config.MethodJmsListenerEndpoint in project spring-framework by spring-projects.
the class EnableJmsTests method composedJmsListeners.
@Test
public void composedJmsListeners() {
try (ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(EnableJmsDefaultContainerFactoryConfig.class, ComposedJmsListenersBean.class)) {
JmsListenerContainerTestFactory simpleFactory = context.getBean("jmsListenerContainerFactory", JmsListenerContainerTestFactory.class);
assertEquals(2, simpleFactory.getListenerContainers().size());
MethodJmsListenerEndpoint first = (MethodJmsListenerEndpoint) simpleFactory.getListenerContainer("first").getEndpoint();
assertEquals("first", first.getId());
assertEquals("orderQueue", first.getDestination());
assertNull(first.getConcurrency());
MethodJmsListenerEndpoint second = (MethodJmsListenerEndpoint) simpleFactory.getListenerContainer("second").getEndpoint();
assertEquals("second", second.getId());
assertEquals("billingQueue", second.getDestination());
assertEquals("2-10", second.getConcurrency());
}
}
use of org.springframework.jms.config.MethodJmsListenerEndpoint in project spring-framework by spring-projects.
the class JmsListenerAnnotationBeanPostProcessorTests method metaAnnotationIsDiscovered.
@Test
public void metaAnnotationIsDiscovered() throws Exception {
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.class, MetaAnnotationTestBean.class);
try {
JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class);
assertEquals("one container should have been registered", 1, factory.getListenerContainers().size());
JmsListenerEndpoint endpoint = factory.getListenerContainers().get(0).getEndpoint();
assertEquals("Wrong endpoint type", MethodJmsListenerEndpoint.class, endpoint.getClass());
MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint) endpoint;
assertEquals(MetaAnnotationTestBean.class, methodEndpoint.getBean().getClass());
assertEquals(MetaAnnotationTestBean.class.getMethod("handleIt", String.class), methodEndpoint.getMethod());
assertEquals(MetaAnnotationTestBean.class.getMethod("handleIt", String.class), methodEndpoint.getMostSpecificMethod());
assertEquals("metaTestQueue", ((AbstractJmsListenerEndpoint) endpoint).getDestination());
} finally {
context.close();
}
}
Aggregations