简体   繁体   中英

Responding NACK on message in Quarkus reactive code cause the readiness check to fail

I am implementing a use case where I listen to messages coming from a Kafka topic in a quarkus application in a reactive manner. I followed as base code the KafkaDeadLetterTopic class from this Gist included on this blogpost https://quarkus.io/blog/kafka-failure-strategy/

When I alter the code to be reactive and return an Uni like this

    @Incoming("movies")
    public Uni<Void> consume1(IncomingKafkaRecord<String, String> movie) {
        return Uni.createFrom().item(movie)
            .onItem()
            .transform(item -> {
                if (movie.getPayload().contains(",")) {
                    throw new IllegalArgumentException(
                        "I don't like movie with , in their title: " + movie);
                }

                return item;
            })
            .onItem().invoke(() -> movie.ack())
            .onFailure().invoke(throwable -> movie.nack(throwable))
            .onItem()
            .ignore().andContinueWithNull();
    }

The messages are still being sent to configured Dead Letter Queue, but the health check is marked as unhealthy, making the application to be restarted by the container orchestrator.

在此处输入图像描述

Is this a bug? Am I using incorrectly the Uni on this case? Is the use of case of sending to DLQ from a reactive code supported?

I tried what Clement suggest and it works nicely. It seems that I wasn't correctly handling error recovery on Mutiny. This is my final code

        @Incoming("movies")
        public Uni<Void> consume1(IncomingKafkaRecord<String, String> movie) {
            return Uni.createFrom().item(movie)
                .onItem()
                .transform(item -> {
                    if (movie.getPayload().contains(",")) {
                        throw new IllegalArgumentException(
                            "I don't like movie with , in their title: " + movie);
                    }

                    return item;
                })
                .onItem().invoke(() -> movie.ack())
                .onItem().ignore().andContinueWithNull()
                .onFailure().recoverWithUni(throwable -> Uni.createFrom().completionStage(movie.nack(throwable)));
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM