Skip to content

Instantly share code, notes, and snippets.

View tomatophobia's full-sized avatar
:octocat:

Youngseo Choi tomatophobia

:octocat:
View GitHub Profile
public static void reactive() {
int seconds = LocalTime.now().getSecond();
Mono<Integer> source;
// 확률적으로 예외 발생
if (seconds % 2 == 0) {
source = Flux.range(1, 10)
.elementAt(5);
}
else if (seconds % 3 == 0) {
source = Flux.range(0, 4)
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);
void shutdownAndAwaitTermination(ExecutorService pool) {
pool.shutdown(); // (1)
try {
if (!pool.awaitTermination(60, TimeUnit.SECONDS)) { // (2)
pool.shutdownNow(); // (3)
if (!pool.awaitTermination(60, TimeUnit.SECONDS)) // (4)
System.err.println("Pool did not terminate"); // (5)
}
} catch (InterruptedException ex) { // (6)
pool.shutdownNow(); // (7)
while (!Thread.currentThread().isInterrupted()) {
try {
System.out.println("interruptible");
Thread.sleep(1000);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
while (!Thread.currentThread().isInterrupted()) {
System.out.println("interruptible");
}
while (true) {
System.out.println("unstoppable");
}
server:
port: 8081
spring:
application:
name: hello-spring
management:
tracing:
sampling:
dependencies {
// Spring MVC를 사용한다고 가정
// 만약 MVC, WebFlux를 모두 사용하지 않는다면 `io.zipkin.reporter2:zipkin-sender-urlconnection` 의존성이 필요합니다.
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'io.micrometer:micrometer-tracing-bridge-brave'
implementation 'io.zipkin.reporter2:zipkin-reporter-brave'
}
2023-07-19T03:05:13.310+09:00 INFO [970f80618600fd0c,82bd574c232efd95] 38985 --- [nio-8081-exec-3] c.easywritten.spring.GreetingController : spring-hi
03:05:12.118 INFO [970f80618600fd0c,970f80618600fd0c] [armeria-common-worker-kqueue-3-2] c.e.armeria.GreetingAnnotatedService - armeria-hi