Class ReactorClientHttpRequestFactory
- All Implemented Interfaces:
org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle, ClientHttpRequestFactory
ClientHttpRequestFactory.
This class implements SmartLifecycle and can be optionally declared
as a Spring-managed bean in order to support JVM Checkpoint Restore.
- Since:
- 6.2
- Author:
- Arjen Poutsma, Juergen Hoeller, Sebastien Deleuze, Brian Clozel
-
Field Summary
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
ConstructorsConstructorDescriptionConstructor with default client, created viaHttpClient.create(), and withcompressionandproxyWithSystemPropertiesenabled.ReactorClientHttpRequestFactory(ReactorResourceFactory resourceFactory, Function<reactor.netty.http.client.HttpClient, reactor.netty.http.client.HttpClient> mapper) Constructor with externally managed Reactor Netty resources, includingLoopResourcesfor event loop threads, andConnectionProviderfor connection pooling.ReactorClientHttpRequestFactory(reactor.netty.http.client.HttpClient client) Constructor with a givenHttpClientinstance. -
Method Summary
Modifier and TypeMethodDescriptioncreateRequest(URI uri, HttpMethod httpMethod) Create a newClientHttpRequestfor the specified URI and HTTP method.intgetPhase()booleanvoidsetConnectTimeout(int connectTimeout) Set the connect timeout value on the underlying client.voidsetConnectTimeout(Duration connectTimeout) Variant ofsetConnectTimeout(int)with aDurationvalue.voidsetExecutor(Executor executor) Set theExecutorto use for performing blocking I/O operations.voidsetReadTimeout(long readTimeout) Variant ofsetReadTimeout(Duration)with a long value.voidsetReadTimeout(Duration timeout) Set the read timeout value on the underlying client.voidstart()voidstop()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.SmartLifecycle
isAutoStartup, isPauseable, stop
-
Constructor Details
-
ReactorClientHttpRequestFactory
public ReactorClientHttpRequestFactory()Constructor with default client, created viaHttpClient.create(), and withcompressionandproxyWithSystemPropertiesenabled. -
ReactorClientHttpRequestFactory
public ReactorClientHttpRequestFactory(reactor.netty.http.client.HttpClient client) Constructor with a givenHttpClientinstance.- Parameters:
client- the client to use
-
ReactorClientHttpRequestFactory
public ReactorClientHttpRequestFactory(ReactorResourceFactory resourceFactory, Function<reactor.netty.http.client.HttpClient, reactor.netty.http.client.HttpClient> mapper) Constructor with externally managed Reactor Netty resources, includingLoopResourcesfor event loop threads, andConnectionProviderfor connection pooling.Generally, it is recommended to share resources for event loop concurrency. This can be achieved either by participating in the JVM-wide, global resources held in
HttpResources, or by using a specific, shared set of resources through aReactorResourceFactorybean. The latter can ensure that resources are shut down when the Spring ApplicationContext is stopped/closed and restarted again (e.g. JVM checkpoint restore).- Parameters:
resourceFactory- the resource factory to get resources frommapper- for further initialization of the client
-
-
Method Details
-
setExecutor
Set theExecutorto use for performing blocking I/O operations.If no executor is provided, the request will use an
elastic scheduler.- Parameters:
executor- the executor to use.- Since:
- 6.2.13
-
setConnectTimeout
public void setConnectTimeout(int connectTimeout) Set the connect timeout value on the underlying client. Effectively, a shortcut forhttpClient.option(CONNECT_TIMEOUT_MILLIS, timeout).By default, set to 30 seconds.
- Parameters:
connectTimeout- the timeout value in millis; use 0 to never time out.- See Also:
-
setConnectTimeout
Variant ofsetConnectTimeout(int)with aDurationvalue. -
setReadTimeout
Set the read timeout value on the underlying client. Effectively, a shortcut forHttpClient.responseTimeout(Duration).By default, set to 10 seconds.
- Parameters:
timeout- the read timeout value in millis; must be > 0.
-
setReadTimeout
public void setReadTimeout(long readTimeout) Variant ofsetReadTimeout(Duration)with a long value. -
createRequest
Description copied from interface:ClientHttpRequestFactoryCreate a newClientHttpRequestfor the specified URI and HTTP method.The returned request can be written to, and then executed by calling
ClientHttpRequest.execute().- Specified by:
createRequestin interfaceClientHttpRequestFactory- Parameters:
uri- the URI to create a request forhttpMethod- the HTTP method to execute- Returns:
- the created request
- Throws:
IOException- in case of I/O errors
-
start
public void start()- Specified by:
startin interfaceorg.springframework.context.Lifecycle
-
stop
public void stop()- Specified by:
stopin interfaceorg.springframework.context.Lifecycle
-
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceorg.springframework.context.Lifecycle
-
getPhase
public int getPhase()- Specified by:
getPhasein interfaceorg.springframework.context.Phased- Specified by:
getPhasein interfaceorg.springframework.context.SmartLifecycle
-