Session is closed in POST endpoint (reactive, mutiny, quarkus, panache)

Viewed 368

I'm using reactive panache with resteasy in a quarkus project and I want to implement a post endpoint hat receives a pojo, returns a 202 (accepted) immediately and stores the pojo in the background. I got it to work based on the provided quarkus example:

@POST
public Uni<Response> create(Fruit fruit) {
    return Panache.<Fruit>withTransaction(fruit::persist)
            .onItem().transform(inserted -> Response.created(URI.create("/fruits/" + inserted.id)).build());
}

But this implementation waits for the persist call to finish. I want to achieve something like this:

@POST
public Uni<Response> createInBackround(Fruit fruit) {
    // Storing a fruit can take some time - Create a pipeline to store the fruit in the background
    Panache.<Fruit>withTransaction(fruit::persist)
       .subscribe().with(savedFruit -> LOG.log(Level.INFO, "Fruit saved successfully!"));
    // Return 202 response immediately to tell the client the request has been accepted
    return Uni.createFrom().item(Response.accepted().build());
}

The second code snippet results in an error that the session is closed:

ERROR [io.qua.mut.run.MutinyInfrastructure] (vert.x-eventloop-thread-9) Mutiny had to drop the following exception: java.lang.IllegalStateException: HR000060: Session is closed

Can anybody help me understand why this is happening?

0 Answers
Related