Replies: 1 comment
-
Solution : Custom Error Handler that prevents acknowledgement (Recommended)Create an error handler that rethrows the exception or signals failure. Custom error handler: import io.micronaut.jms.listener.error.JMSListenerErrorHandler;
import jakarta.inject.Singleton;
import jakarta.jms.Message;
import jakarta.jms.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Singleton
public class RethrowingJMSListenerErrorHandler implements JMSListenerErrorHandler {
private static final Logger log = LoggerFactory.getLogger(RethrowingJMSListenerErrorHandler.class);
@Override
public void handle(Session session, Message message, Throwable ex) throws Throwable {
log.error("Failed to handle message - rethrowing to prevent acknowledgement", ex);
// Rethrow to trigger callbackFailed = true and prevent ack
throw ex;
}
}Register it (application.yml): jms:
sqs:
default:
error-handler-bean-name: rethrowingJMSListenerErrorHandlerOr register globally via configuration: import io.micronaut.context.annotation.Bean;
import io.micronaut.context.annotation.Factory;
import io.micronaut.jms.listener.error.JMSListenerErrorHandler;
import jakarta.inject.Singleton;
@Factory
public class JmsErrorHandlerFactory {
@Bean
@Singleton
public JMSListenerErrorHandler jmsListenerErrorHandler() {
return new RethrowingJMSListenerErrorHandler();
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Using
jakarta.jms3.1.0 andmicronaut-jms-sqs4.1.0Is it expected behaviour for micronaut to acknowledge the message when RuntimeException is thrown? Sample:
JMSListener handleMessage(Message msg)code for errors:the exception is catched by the
LoggingJMSListenerErrorHandler- the default error handler - and it is swallowed:exception is not propagated and then in `SQSSessionCallbackScheduler:
Beta Was this translation helpful? Give feedback.
All reactions