webflux와 비동기처리에 대한 설명이 자세하다.
webClient를 처음 사용해보기도 했고, exception(m1 관련)도 발생해서 이것저것 삽질도 많이해보았다.
.bodyToMono(NaviResponse.class);
CountDownLatch
가 없다면, NaviResponse에 응답 값이 들어오기전에 다른 메서드들이 실행되기 때문에, api 응답에 빈 리스트만 반환된다.CountDownLatch.await()
를 통해서 모든 스레드가 일 처리를 완료할 때까지(응답 값을 채울때까지) 기다리게 할 수 있다.NaviResponseMono.log()
메서드를 통해서 비동기 처리에대한 log를 확인할 수 있다. 2022-06-11 19:21:04.750 INFO 44982 --- [nio-8080-exec-1] reactor.Mono.FlatMap.1 : | onSubscribe([Fuseable] MonoFlatMap.FlatMapMain)
2022-06-11 19:21:04.751 INFO 44982 --- [nio-8080-exec-1] reactor.Mono.FlatMap.1 : | request(unbounded)
2022-06-11 19:21:05.233 INFO 44982 --- [nio-8080-exec-1] reactor.Mono.FlatMap.2 : | onSubscribe([Fuseable] MonoFlatMap.FlatMapMain)
2022-06-11 19:21:05.233 INFO 44982 --- [nio-8080-exec-1] reactor.Mono.FlatMap.2 : | request(unbounded)
2022-06-11 19:21:05.234 INFO 44982 --- [nio-8080-exec-1] reactor.Mono.FlatMap.3 : | onSubscribe([Fuseable] MonoFlatMap.FlatMapMain)
2022-06-11 19:21:05.234 INFO 44982 --- [nio-8080-exec-1] reactor.Mono.FlatMap.3 : | request(unbounded)
2022-06-11 19:21:05.235 INFO 44982 --- [nio-8080-exec-1] reactor.Mono.FlatMap.4 : | onSubscribe([Fuseable] MonoFlatMap.FlatMapMain)
2022-06-11 19:21:05.235 INFO 44982 --- [nio-8080-exec-1] reactor.Mono.FlatMap.4 : | request(unbounded)
2022-06-11 19:21:05.235 INFO 44982 --- [nio-8080-exec-1] reactor.Mono.FlatMap.5 : | onSubscribe([Fuseable] MonoFlatMap.FlatMapMain)
2022-06-11 19:21:05.235 INFO 44982 --- [nio-8080-exec-1] reactor.Mono.FlatMap.5 : | request(unbounded)
2022-06-11 19:21:05.236 INFO 44982 --- [nio-8080-exec-1] reactor.Mono.FlatMap.6 : | onSubscribe([Fuseable] MonoFlatMap.FlatMapMain)
2022-06-11 19:21:05.236 INFO 44982 --- [nio-8080-exec-1] reactor.Mono.FlatMap.6 : | request(unbounded)
2022-06-11 19:21:05.237 INFO 44982 --- [nio-8080-exec-1] reactor.Mono.FlatMap.7 : | onSubscribe([Fuseable] MonoFlatMap.FlatMapMain)
2022-06-11 19:21:05.237 INFO 44982 --- [nio-8080-exec-1] reactor.Mono.FlatMap.7 : | request(unbounded)
2022-06-11 19:21:05.237 INFO 44982 --- [nio-8080-exec-1] reactor.Mono.FlatMap.8 : | onSubscribe([Fuseable] MonoFlatMap.FlatMapMain)
2022-06-11 19:21:05.237 INFO 44982 --- [nio-8080-exec-1] reactor.Mono.FlatMap.8 : | request(unbounded)
2022-06-11 19:21:05.693 INFO 44982 --- [ctor-http-nio-2] reactor.Mono.FlatMap.1 : | onNext(NaviResponse(infos=[NaviInfo(code=0, summary=Summary(distance=7073.0, duration=1233.0))]))
2022-06-11 19:21:05.695 INFO 44982 --- [ctor-http-nio-2] reactor.Mono.FlatMap.1 : | onComplete()
2022-06-11 19:21:06.212 INFO 44982 --- [ctor-http-nio-4] reactor.Mono.FlatMap.3 : | onNext(NaviResponse(infos=[NaviInfo(code=0, summary=Summary(distance=42369.0, duration=4560.0))]))
2022-06-11 19:21:06.212 INFO 44982 --- [ctor-http-nio-4] reactor.Mono.FlatMap.3 : | onComplete()
2022-06-11 19:21:06.229 INFO 44982 --- [ctor-http-nio-3] reactor.Mono.FlatMap.2 : | onNext(NaviResponse(infos=[NaviInfo(code=0, summary=Summary(distance=61847.0, duration=4763.0))]))
2022-06-11 19:21:06.230 INFO 44982 --- [ctor-http-nio-3] reactor.Mono.FlatMap.2 : | onComplete()
2022-06-11 19:21:06.517 INFO 44982 --- [ctor-http-nio-5] reactor.Mono.FlatMap.4 : | onNext(NaviResponse(infos=[NaviInfo(code=0, summary=Summary(distance=227785.0, duration=9247.0))]))
2022-06-11 19:21:06.517 INFO 44982 --- [ctor-http-nio-5] reactor.Mono.FlatMap.4 : | onComplete()
2022-06-11 19:21:06.635 INFO 44982 --- [ctor-http-nio-7] reactor.Mono.FlatMap.6 : | onNext(NaviResponse(infos=[NaviInfo(code=0, summary=Summary(distance=221692.0, duration=10417.0))]))
2022-06-11 19:21:06.636 INFO 44982 --- [ctor-http-nio-7] reactor.Mono.FlatMap.6 : | onComplete()
2022-06-11 19:21:06.827 INFO 44982 --- [ctor-http-nio-1] reactor.Mono.FlatMap.8 : | onNext(NaviResponse(infos=[NaviInfo(code=0, summary=Summary(distance=343916.0, duration=13146.0))]))
2022-06-11 19:21:06.827 INFO 44982 --- [ctor-http-nio-1] reactor.Mono.FlatMap.8 : | onComplete()
2022-06-11 19:21:07.234 INFO 44982 --- [ctor-http-nio-8] reactor.Mono.FlatMap.7 : | onNext(NaviResponse(infos=[NaviInfo(code=0, summary=Summary(distance=354964.0, duration=14933.0))]))
2022-06-11 19:21:07.235 INFO 44982 --- [ctor-http-nio-8] reactor.Mono.FlatMap.7 : | onComplete()
2022-06-11 19:21:07.310 INFO 44982 --- [ctor-http-nio-6] reactor.Mono.FlatMap.5 : | onNext(NaviResponse(infos=[NaviInfo(code=0, summary=Summary(distance=406501.0, duration=15768.0))]))
2022-06-11 19:21:07.311 INFO 44982 --- [ctor-http-nio-6] reactor.Mono.FlatMap.5 : | onComplete()