RestTemplate
, WebClient
등이 있다.RestTemplate restTemplate = new RestTemplate();
ResponseEntity<String> responseEntity = restTemplate.exchange(uriComponents.toUri(), httpMethod, httpEntity, String.class);
Non-Blocking I/O
모델을 기반으로 하며, 비동기 및 리액티브 스트림 처리를 지원RestTemplate
의 대안으로 제공되며, 더 나은 확장성과 성능을 제공한다.// 출처: https://hahahoho5915.tistory.com/79 [넌 잘하고 있어:티스토리]
WebClient webClient = WebClient.create();
String url = "https://api.example.com/users/{id}";
Mono<User> userMono = webClient.get()
.uri(url, 1)
.retrieve()
.bodyToMono(User.class);
✅ 동기(Synchronous) vs 비동기(Asynchronous)
Thread1
이 작업을 시작 시키고, Task1
이 모두 진행 될때까지 Task2
는 대기해야한다.return
값과 동일하다.Thread1
이 작업을 시작 시키면, 완료를 기다리지 않고, Thread1
이 완료되지 않더라도 Task2
를 진행 시킬 수 있다.호출되는 함수의 작업 완료 여부(응답 상태)를 누가 신경쓰느냐가 관심사이다.
✅ blocking vs non-blocking
주로 IO의 읽기, 쓰기에서 사용된다
호출되는 함수가 바로 return하느냐 마느냐가 관심사이다.
출처
JAVA(spring) - HTTP 통신 방식 3가지(RestTemplate, WebClient, OpenFeign)
[Spring] RestTemplate과 WebClient 이해하기
동기 vs 비동기 (feat. blocking vs non-blocking)
동기, 비동기 처리