Sunfile
Sunfile

Reputation: 125

Advice for the Quarkus way for fireandforget a long running method via a rest-endpoint

I've created a rest endpoint which returns immediately a 202. In the meantime it uses Vertx eventbus to add an event to the bus. Another method which uses the @ConsumeEvent annotation starts a process which takes a long time. This was the solution so far for triggering a method via a restendpoint in a fireandforget fashion.

The longrunning method does multiple httpcalls via microprofile restclient. However, I just found out that when an exception is thrown as a response from such a restclient, the whole process exits and no error is shown in any log. I've tried registering an exceptionHandler for the restclient but that doesn't make a difference, the thread just stops.

My question: is this the best way in Quarkus to trigger longer running functions and return a 202 immediately to the caller? If yes, how can I implement exception handling in the method, and methods called by that method in the @ConsumeEvent process.

Setup:

Controller class:

....

@Inject
EventBus bus;

@Inject
ProcessingService service;

@POST
@NonBlocking
public Response start(String body) {
  bus.request("topic", body);
  return Response.accepted.build();
}

@Blocking
@ConsumeEvent("topic")
public void processing(String body) {
  service.start(body);
}
@RequestScoped
public class ProcessingService {

  @Inject
  @RestClient
  TestClient client;

  public void start(String body) {
    ... do some long running things
    ... which might throw an exception
    client.call(body);
  }
}

Upvotes: 0

Views: 187

Answers (1)

Sunfile
Sunfile

Reputation: 125

Even though an ExceptionHandler was used, I wasn't catching the runtime error thrown by that. By implementing a try/catch block around each restclient call, the issue is now resolved.

Upvotes: 0

Related Questions