0

I'm new to quarkus and reactive programming. I'm currently facing an issue with quarkus-reactive-postgresql extension.

I have a list containing events that perform a database update. Each event has to be updated independently (so I don't use a transaction).

Here is my web service:

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public Uni<JsonObject> synchro(List<Event> events) {
        List<Uni<RowSet<Row>>> queries = new ArrayList<>();
        List<Event> success = new ArrayList<>();
        List<Event> fails = new ArrayList<>();
        for (Event evt : events) {
            // Perform update
            var query = client.preparedQuery("My failing query")
                    .execute(Tuple.of(evt.field));

            // Subscribe. It's ok. Add event to success list
            query.subscribe().with(unused -> success.add(evt));

            // It's failure. Add event to failures
            query.onFailure(throwable -> {
                log.error(String.format("Unable to update event %s", evt.toString()), throwable);
                fails.add(evt);
                return true;
            });

            queries.add(query);
        }

        return Uni.combine().all().unis(queries)
                .combinedWith(ArrayList::new)
                .onItem().transform(list -> new JsonObject()
                        .put("success", success.stream().map(Event::toJson).collect(Collectors.toList()))
                        .put("errors", fails.stream().map(Event::toJson).collect(Collectors.toList()))
                );
    }

Quarkus reactive pg extension throws an exception :

2021-08-06 10:35:37,665 ERROR [io.qua.mut.run.MutinyInfrastructure] (vert.x-eventloop-thread-23) Mutiny had to drop the following exception: io.vertx.pgclient.PgException: { "message": "column \"fake_column\" of relation \"table\" does not exist", "severity": "ERROR", "code": "42703", "position": "18", "file": "analyze.c", "line": "2263", "routine": "transformUpdateTargetList" }

However, .onFailure is not triggered and ever fill my failures list.

Is it a bug or something goes wrong with my code ?

Thanks for your help,

3
  • Try puting the onFailure before the suscribe and chaining everything. The suscribe launches the computation and you are adding the on failure later Commented Aug 6, 2021 at 9:10
  • Thanks for your reply. I already try it but it does not fix the issue. Maybe it's a bug from quarkus reactive pg extension ? Commented Aug 6, 2021 at 9:36
  • I'm not so sure, if you can create a reproducer, your best bet is open a bug report, they tend to reply quite fast. I think it might something simple that we are not seeing. Commented Aug 6, 2021 at 9:42

1 Answer 1

0

In case someone is struggling with this as I did, you can try adding the following code:

.onFailure().transform(ex -> {
    if (ex.getClass().equals(PgException.class)) {
        //here you can do log and stuff
        //in case, you only need to return this boolean you can create 
        //custom handler for your custom exception
        return new CustomException(ex);
    }else{
        return new Exception(ex);
    });    

transform() function somehow lets you return an exception no matter what your method was supposed to return, here is some resource for it: https://cescoffier.github.io/mutiny-doc-sandbox/getting-started/handling-failures

Concerning handling the exception, here is a source that really helped me: https://howtodoinjava.com/resteasy/resteasy-exceptionmapper-example/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.