Handling Consumer Exceptions Rabbit MQ Micronaut 2.2.1

412 views Asked by At

Trying to implement the Handling Consumer Exceptions in Micronaut 2.2.1 https://micronaut-projects.github.io/micronaut-rabbitmq/latest/guide/#consumerExceptions

As per the documentation

If the consumer bean implements RabbitListenerExceptionHandler, then exceptions will be sent to the method implementation.

If the consumer bean does not implement RabbitListenerExceptionHandler, then the exceptions will be routed to the primary exception handler bean. To override the default exception handler, replace the DefaultRabbitListenerExceptionHandler with your own implementation that is designated as @Primary.

@Singleton
@Primary
public class RabbitListenerExceptionHandler implements io.micronaut.rabbitmq.exception.RabbitListenerExceptionHandler {
    private static final Logger LOG = LoggerFactory.getLogger(RabbitListenerExceptionHandler.class);
    @Override
    public void handle(RabbitListenerException exception) {
        if (LOG.isErrorEnabled()) {
            Optional<RabbitConsumerState> messageState = exception.getMessageState();
            if (messageState.isPresent()) {
                LOG.error("Error processing a message for RabbitMQ consumer [" + exception.getListener() + "]", exception);
            } else {
                LOG.error("RabbitMQ consumer [" + exception.getListener() + "] produced an error", exception);
            }
        }
    }
}

Exception at run time

Caused by: io.micronaut.context.exceptions.NonUniqueBeanException: Multiple possible bean candidates found: [io.micronaut.rabbitmq.exception.DefaultRabbitListenerExceptionHandler, fete.bird.common.extension.RabbitListenerExceptionHandler]

How can I override the RabbitListenerExceptionHandler ??

1

There are 1 answers

0
James Kleeh On BEST ANSWER

You have to replace the default implementation with @Replaces(DefaultRabbitListenerExceptionHandler.class)