Skip to content

Commit

Permalink
➕ Chore: WebClientConfig dependency 누락 반영 (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
win-luck committed Oct 15, 2023
1 parent af26095 commit ca7e9f5
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/main/java/com/diareat/diareat/auth/config/WebClientConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.diareat.diareat.auth.config;

import io.netty.channel.ChannelOption;
import io.netty.handler.timeout.ReadTimeoutHandler;
import io.netty.handler.timeout.WriteTimeoutHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.reactive.ClientHttpConnector;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.http.client.reactive.ReactorResourceFactory;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.netty.http.client.HttpClient;

import java.time.Duration;
import java.util.function.Function;

@Configuration
public class WebClientConfig {

@Bean
public ReactorResourceFactory resourceFactory() {
ReactorResourceFactory factory = new ReactorResourceFactory();
factory.setUseGlobalResources(false);
return factory;
}

@Bean
public WebClient webClient() {
Function<HttpClient, HttpClient> mapper = client -> HttpClient.create()
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1000)
.doOnConnected(connection -> connection.addHandlerLast(new ReadTimeoutHandler(10))
.addHandlerLast(new WriteTimeoutHandler(10)))
.responseTimeout(Duration.ofSeconds(1));

ClientHttpConnector connector =
new ReactorClientHttpConnector(resourceFactory(), mapper);
return WebClient.builder().clientConnector(connector).build();
}
}

0 comments on commit ca7e9f5

Please sign in to comment.