Search in sources :

Example 1 with MessageAcknowledgementException

use of io.micronaut.messaging.exceptions.MessageAcknowledgementException in project micronaut-jms by micronaut-projects.

the class AbstractJMSListenerMethodProcessor method generateAndBindListener.

@SuppressWarnings("unchecked")
private MessageListener generateAndBindListener(Object bean, ExecutableMethod<?, ?> method, ExecutorService executor, boolean acknowledge) {
    return message -> executor.submit(() -> {
        try {
            DefaultExecutableBinder<Message> binder = new DefaultExecutableBinder<>();
            BoundExecutable boundExecutable = binder.bind(method, jmsArgumentBinderRegistry, message);
            boundExecutable.invoke(bean);
            if (acknowledge) {
                try {
                    message.acknowledge();
                } catch (JMSException e) {
                    logger.error("Failed to acknowledge receipt of message with the broker. " + "This message may be falsely retried.", e);
                    throw new MessageAcknowledgementException(e.getMessage(), e);
                }
            }
        } catch (Exception e) {
            logger.error("Failed to process a message: " + message + " " + e.getMessage(), e);
        }
    });
}
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) DefaultExecutableBinder(io.micronaut.core.bind.DefaultExecutableBinder) BoundExecutable(io.micronaut.core.bind.BoundExecutable) JMSException(javax.jms.JMSException) MessageAcknowledgementException(io.micronaut.messaging.exceptions.MessageAcknowledgementException) MessageAcknowledgementException(io.micronaut.messaging.exceptions.MessageAcknowledgementException) JMSException(javax.jms.JMSException)

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