Search in sources :

Example 1 with JMSListenerContainerFactory

use of io.micronaut.jms.listener.JMSListenerContainerFactory in project micronaut-jms by micronaut-projects.

the class AbstractJMSListenerMethodProcessor method registerListener.

private void registerListener(ExecutableMethod<?, ?> method, String connectionFactoryName, BeanDefinition<?> beanDefinition, AnnotationValue<T> destinationAnnotation, JMSDestinationType type) {
    validateArguments(method);
    final Class<?> targetClass = Stream.of(method.getArguments()).filter(arg -> arg.isDeclaredAnnotationPresent(MessageBody.class) || arg.isDeclaredAnnotationPresent(io.micronaut.jms.annotations.Message.class)).findAny().map(Argument::getClass).get();
    final String destination = destinationAnnotation.getRequiredValue(String.class);
    final int acknowledgeMode = destinationAnnotation.getRequiredValue("acknowledgeMode", Integer.class);
    final boolean transacted = destinationAnnotation.getRequiredValue("transacted", Boolean.class);
    final JMSListenerContainerFactory listenerFactory = beanContext.findBean(JMSListenerContainerFactory.class).orElseThrow(() -> new IllegalStateException("No JMSListenerFactory configured"));
    final JMSConnectionPool connectionPool = beanContext.getBean(JMSConnectionPool.class, Qualifiers.byName(connectionFactoryName));
    final Object bean = beanContext.findBean(beanDefinition.getBeanType()).get();
    final ExecutorService executor = getExecutorService(destinationAnnotation);
    MessageListener listener = generateAndBindListener(bean, method, executor, CLIENT_ACKNOWLEDGE == acknowledgeMode);
    listenerFactory.registerListener(connectionPool, destination, listener, targetClass, transacted, acknowledgeMode, type);
}
Also used : JMSListener(io.micronaut.jms.annotations.JMSListener) BeanContext(io.micronaut.context.BeanContext) JMSConnectionPool(io.micronaut.jms.pool.JMSConnectionPool) LoggerFactory(org.slf4j.LoggerFactory) MessageListener(javax.jms.MessageListener) ExecutableMethod(io.micronaut.inject.ExecutableMethod) JMSDestinationType(io.micronaut.jms.model.JMSDestinationType) JMSListenerContainerFactory(io.micronaut.jms.listener.JMSListenerContainerFactory) Argument(io.micronaut.core.type.Argument) BoundExecutable(io.micronaut.core.bind.BoundExecutable) Message(javax.jms.Message) DefaultExecutableBinder(io.micronaut.core.bind.DefaultExecutableBinder) ExecutorService(java.util.concurrent.ExecutorService) MessageAcknowledgementException(io.micronaut.messaging.exceptions.MessageAcknowledgementException) Logger(org.slf4j.Logger) Qualifiers(io.micronaut.inject.qualifiers.Qualifiers) ExecutableMethodProcessor(io.micronaut.context.processor.ExecutableMethodProcessor) JMSException(javax.jms.JMSException) Assert(io.micronaut.jms.util.Assert) Stream(java.util.stream.Stream) AnnotationValue(io.micronaut.core.annotation.AnnotationValue) Annotation(java.lang.annotation.Annotation) BeanDefinition(io.micronaut.inject.BeanDefinition) JMSArgumentBinderRegistry(io.micronaut.jms.bind.JMSArgumentBinderRegistry) MessageBody(io.micronaut.messaging.annotation.MessageBody) CLIENT_ACKNOWLEDGE(javax.jms.Session.CLIENT_ACKNOWLEDGE) Message(javax.jms.Message) MessageListener(javax.jms.MessageListener) JMSConnectionPool(io.micronaut.jms.pool.JMSConnectionPool) JMSListenerContainerFactory(io.micronaut.jms.listener.JMSListenerContainerFactory) ExecutorService(java.util.concurrent.ExecutorService) MessageBody(io.micronaut.messaging.annotation.MessageBody)

Aggregations

BeanContext (io.micronaut.context.BeanContext)1 ExecutableMethodProcessor (io.micronaut.context.processor.ExecutableMethodProcessor)1 AnnotationValue (io.micronaut.core.annotation.AnnotationValue)1 BoundExecutable (io.micronaut.core.bind.BoundExecutable)1 DefaultExecutableBinder (io.micronaut.core.bind.DefaultExecutableBinder)1 Argument (io.micronaut.core.type.Argument)1 BeanDefinition (io.micronaut.inject.BeanDefinition)1 ExecutableMethod (io.micronaut.inject.ExecutableMethod)1 Qualifiers (io.micronaut.inject.qualifiers.Qualifiers)1 JMSListener (io.micronaut.jms.annotations.JMSListener)1 JMSArgumentBinderRegistry (io.micronaut.jms.bind.JMSArgumentBinderRegistry)1 JMSListenerContainerFactory (io.micronaut.jms.listener.JMSListenerContainerFactory)1 JMSDestinationType (io.micronaut.jms.model.JMSDestinationType)1 JMSConnectionPool (io.micronaut.jms.pool.JMSConnectionPool)1 Assert (io.micronaut.jms.util.Assert)1 MessageBody (io.micronaut.messaging.annotation.MessageBody)1 MessageAcknowledgementException (io.micronaut.messaging.exceptions.MessageAcknowledgementException)1 Annotation (java.lang.annotation.Annotation)1 ExecutorService (java.util.concurrent.ExecutorService)1 Stream (java.util.stream.Stream)1