REST-Endpoint: Async execution without return value

后端 未结 2 1966
我寻月下人不归
我寻月下人不归 2021-01-20 10:11

My problem might be very easy to solve, but I don\'t get it at the moment. In my Quarkus-App I have a REST-Endpoint which should call a method, don\'t wait for the result an

相关标签:
2条回答
  • 2021-01-20 10:57

    We've found a solution:

    @POST
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public Response calculateAsync(String input) {
        Uni.createFrom().item(input).emitOn(Infrastructure.getDefaultWorkerPool()).subscribe().with(
                item -> process(input), Throwable::printStackTrace
        );
    
        return Response.accepted().build();
    }
    
    0 讨论(0)
  • 2021-01-20 11:09

    You can use @Suspended AsyncResponse response in parameters and make the method return void Here's example of a similar method:

        @GET
        @Produces(MediaType.TEXT_PLAIN)
        public void hello(@Suspended AsyncResponse response) throws InterruptedException {
            response.resume(Response.ok().build());
            Thread.sleep(10000);
            System.out.println("Do some work");
        }
    
    0 讨论(0)
提交回复
热议问题