-
SpringBoot webClientSpring 2022. 2. 9. 16:19
이제 webClient 적용을 피할수 없게 되었다.
webFlux, reactor 관련해서 좀더 자세히 공부를 해야겠다.
https://happycloud-lee.tistory.com/220
https://docs.spring.io/spring-framework/docs/current/reference/html/web-reactive.html#webflux-client
WebClient client = WebClient.create(); // DefaultWebClientBuilder @Override public WebClient build() { ClientHttpConnector connectorToUse = (this.connector != null ? this.connector : initConnector()); ExchangeFunction exchange = (this.exchangeFunction == null ? ExchangeFunctions.create(connectorToUse, initExchangeStrategies()) : this.exchangeFunction); ExchangeFunction filteredExchange = (this.filters != null ? this.filters.stream() .reduce(ExchangeFilterFunction::andThen) .map(filter -> filter.apply(exchange)) .orElse(exchange) : exchange); HttpHeaders defaultHeaders = copyDefaultHeaders(); MultiValueMap<String, String> defaultCookies = copyDefaultCookies(); return new DefaultWebClient(filteredExchange, initUriBuilderFactory(), defaultHeaders, defaultCookies, this.defaultRequest, new DefaultWebClientBuilder(this)); } DefaultWebClient(ExchangeFunction exchangeFunction, UriBuilderFactory uriBuilderFactory, @Nullable HttpHeaders defaultHeaders, @Nullable MultiValueMap<String, String> defaultCookies, @Nullable Consumer<RequestHeadersSpec<?>> defaultRequest, DefaultWebClientBuilder builder) { this.exchangeFunction = exchangeFunction; this.uriBuilderFactory = uriBuilderFactory; this.defaultHeaders = defaultHeaders; this.defaultCookies = defaultCookies; this.defaultRequest = defaultRequest; this.builder = builder; }
https://github.com/reactor/reactor-netty
httpClient 구현체가 netty-http로 바뀌었다.
//DefaultWebClientBuilder.java private ClientHttpConnector initConnector() { if (reactorClientPresent) { return new ReactorClientHttpConnector(); } else if (jettyClientPresent) { return new JettyClientHttpConnector(); } else if (httpComponentsClientPresent) { return new HttpComponentsClientHttpConnector(); } throw new IllegalStateException("No suitable default ClientHttpConnector found"); } @Override public WebClient build() { ClientHttpConnector connectorToUse = (this.connector != null ? this.connector : initConnector()); ExchangeFunction exchange = (this.exchangeFunction == null ? ExchangeFunctions.create(connectorToUse, initExchangeStrategies()) : this.exchangeFunction); ExchangeFunction filteredExchange = (this.filters != null ? this.filters.stream() .reduce(ExchangeFilterFunction::andThen) .map(filter -> filter.apply(exchange)) .orElse(exchange) : exchange); HttpHeaders defaultHeaders = copyDefaultHeaders(); MultiValueMap<String, String> defaultCookies = copyDefaultCookies(); return new DefaultWebClient(filteredExchange, initUriBuilderFactory(), defaultHeaders, defaultCookies, this.defaultRequest, new DefaultWebClientBuilder(this)); }
httpClient.create()에서 pool을 따로 안 만들어주면 모든 요청이 하나의 이벤트 루프 큐로 들어가는것 주의
'Spring' 카테고리의 다른 글
Spring MVC, Boot (0) 2022.02.08 좀더 재밌게 Spring, 개발을 공부하는 순서 (0) 2022.02.06