|
| 1 | +/* |
| 2 | + * Copyright 2012-2019 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.boot.docs.web.reactive.function.client; |
| 18 | + |
| 19 | +import io.netty.channel.ChannelOption; |
| 20 | +import io.netty.handler.timeout.ReadTimeoutHandler; |
| 21 | +import reactor.netty.http.client.HttpClient; |
| 22 | +import reactor.netty.tcp.TcpClient; |
| 23 | + |
| 24 | +import org.springframework.context.annotation.Bean; |
| 25 | +import org.springframework.context.annotation.Configuration; |
| 26 | +import org.springframework.http.client.reactive.ClientHttpConnector; |
| 27 | +import org.springframework.http.client.reactive.ReactorClientHttpConnector; |
| 28 | +import org.springframework.http.client.reactive.ReactorResourceFactory; |
| 29 | +import org.springframework.web.reactive.function.client.WebClient; |
| 30 | + |
| 31 | +/** |
| 32 | + * Example configuration for customizing the Reactor Netty-based {@link WebClient}. |
| 33 | + * |
| 34 | + * @author Andy Wilkinson |
| 35 | + */ |
| 36 | +@Configuration |
| 37 | +public class ReactorNettyClientCustomizationExample { |
| 38 | + |
| 39 | + // tag::custom-http-connector[] |
| 40 | + @Bean |
| 41 | + ClientHttpConnector clientHttpConnector(ReactorResourceFactory resourceFactory) { |
| 42 | + TcpClient tcpClient = TcpClient.create(resourceFactory.getConnectionProvider()) |
| 43 | + .runOn(resourceFactory.getLoopResources()).option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 60000) |
| 44 | + .doOnConnected((connection) -> connection.addHandlerLast(new ReadTimeoutHandler(60))); |
| 45 | + return new ReactorClientHttpConnector(HttpClient.from(tcpClient)); |
| 46 | + } |
| 47 | + // end::custom-http-connector[] |
| 48 | + |
| 49 | +} |
0 commit comments