Created
August 5, 2023 17:11
-
-
Save tomatophobia/486eb752bce3de9f5c16027e34dc0060 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ServerBuilder sb = ...; | |
| sb.service("/api", (ctx, req) -> { | |
| CompletableFuture<HttpResponse> future = new CompletableFuture<>(); | |
| HttpResponse authResponse = authClient.execute(req.headers()); | |
| // 서드파티 API의 응답을 다른 쓰레드에서 비동기로 처리한다. | |
| authResponse.aggregate().thenAccept(aggregatedRes -> { | |
| // 요청 컨텍스트 정보를 명시적으로 전달한다. | |
| try (SafeCloseable ignored = ctx.push()) { | |
| HttpResponse response = backendClient.execute(req); | |
| future.complete(response); | |
| } | |
| }); | |
| return HttpResponse.from(future); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment