1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- //package com.backendsys.service.HttpTodo;
- //
- //import io.netty.channel.ChannelOption;
- //import io.netty.handler.timeout.ReadTimeoutHandler;
- //import io.netty.handler.timeout.WriteTimeoutHandler;
- //import lombok.SneakyThrows;
- //import org.springframework.beans.factory.annotation.Value;
- //import org.springframework.context.annotation.Bean;
- //import org.springframework.context.annotation.Configuration;
- //import org.springframework.http.HttpStatusCode;
- //import org.springframework.web.reactive.function.client.WebClient;
- //import org.springframework.web.reactive.function.client.support.WebClientAdapter;
- //import org.springframework.web.service.invoker.HttpServiceProxyFactory;
- //import reactor.core.publisher.Mono;
- //import reactor.netty.http.client.HttpClient;
- //
- // // 全局配置,仅可用于同一个域的配置
- //
- //@Configuration
- //public class HttpTodoConfig {
- //
- // // 引用配置变量
- // @Value("${HTTP_ACTUATOR_URI}")
- // private String baseUrl;
- //
- // // 定制Http服务
- // @Bean
- // public WebClient webClient() {
- //
- // System.out.println("========= webClient ===========");
- //
- // HttpClient httpClient = HttpClient.create()
- // .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 30 * 1000) // 连接时间 3W 毫秒
- // .doOnConnected(conn -> {
- // conn.addHandlerLast(new ReadTimeoutHandler(10)); // 读超时 10秒
- // conn.addHandlerLast(new WriteTimeoutHandler(10)); // 写超时 10秒
- // });
- //
- //
- // return WebClient.builder()
- // .baseUrl(baseUrl)
- // .defaultStatusHandler(HttpStatusCode::isError, clientResponse -> {
- // System.out.println("WebClient defaultStatusHandler:");
- // System.out.println(clientResponse.statusCode());
- // return Mono.error(new RuntimeException(clientResponse.statusCode().toString()));
- // })
- // //.defaultStatusHandler(HttpStatusCode::is4xxClientError,
- // // error -> Mono.error(new RuntimeException("API not found")))
- // //.defaultStatusHandler(HttpStatusCode::is5xxServerError,
- // // error -> Mono.error(new RuntimeException("Server is not responding")))
- // .build();
- // }
- //
- // // 创建代理
- // @SneakyThrows
- // @Bean
- // public HttpTodoService requestTodoService(WebClient webClient) {
- // HttpServiceProxyFactory httpServiceProxyFactory = HttpServiceProxyFactory.builder(WebClientAdapter.forClient(webClient)).build();
- // return httpServiceProxyFactory.createClient(HttpTodoService.class);
- // }
- //
- //}
|