Class ReactorClientHttpRequestFactory
- All Implemented Interfaces:
Lifecycle, Phased, 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 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()Return the phase that this lifecycle object is supposed to run in.booleanCheck whether this component is currently running.voidsetConnectTimeout(int connectTimeout) Set the connect timeout on the underlying client, in milliseconds.voidsetConnectTimeout(Duration connectTimeout) Set the connect timeout on the underlying client, as aDuration.voidsetExecutor(Executor executor) Set theExecutorto use for performing blocking I/O operations.voidsetReadTimeout(long readTimeout) Set the read timeout on the underlying client, in milliseconds.voidsetReadTimeout(Duration readTimeout) Set the read timeout on the underlying client, as aDuration.voidstart()Start this component.voidstop()Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface 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 on the underlying client, in milliseconds.Effectively, a shortcut for
httpClient.option(CONNECT_TIMEOUT_MILLIS, connectTimeout).A timeout value of 0 specifies an infinite timeout.
Negative values are not permitted.
Default is 30 seconds, as defined by Reactor Netty.
- Parameters:
connectTimeout- the connect timeout in milliseconds- See Also:
-
setConnectTimeout
Set the connect timeout on the underlying client, as aDuration.Effectively, a shortcut for
httpClient.option(CONNECT_TIMEOUT_MILLIS, connectTimeout.toMillis()).A timeout value of 0 specifies an infinite timeout.
Negative values and values less than one millisecond (other than 0) are not permitted, and values exceeding
Integer.MAX_VALUEmilliseconds are limited toInteger.MAX_VALUEmilliseconds.Default is 30 seconds, as defined by Reactor Netty.
- Parameters:
connectTimeout- the connect timeout as aDuration- See Also:
-
setReadTimeout
Set the read timeout on the underlying client, as aDuration.Effectively, a shortcut for
HttpClient.responseTimeout(Duration).A timeout value of 0 specifies an infinite timeout.
Negative values and values less than one millisecond (other than 0) are not permitted.
Default is 10 seconds, unless a pre-configured
HttpClientis supplied.- Parameters:
readTimeout- the read timeout as aDuration- See Also:
-
setReadTimeout
public void setReadTimeout(long readTimeout) Set the read timeout on the underlying client, in milliseconds.Effectively, a shortcut for
httpClient.responseTimeout(Duration.ofMillis(readTimeout)).A timeout value of 0 specifies an infinite timeout.
Negative values are not permitted.
Default is 10 seconds, unless a pre-configured
HttpClientis supplied.- Parameters:
readTimeout- the read timeout in milliseconds- See Also:
-
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()Description copied from interface:LifecycleStart this component.Should not throw an exception if the component is already running.
In the case of a container, this will propagate a hard start signal to all components that apply, even to non-auto-startup components.
-
stop
public void stop()Description copied from interface:LifecycleStop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method. Consider implementingSmartLifecycleand itsstop(Runnable)variant when asynchronous stop behavior is necessary.Note that this stop notification is not guaranteed to come before destruction: On regular shutdown,
Lifecyclebeans will first receive a stop notification before the general destruction callbacks are being propagated; however, on hot refresh during a context's lifetime or on aborted refresh attempts, a given bean's destroy method will be called without any consideration of stop signals upfront.Should not throw an exception if the component is not running (not started yet).
In the case of a container, this will propagate the stop signal to all components that apply.
-
isRunning
public boolean isRunning()Description copied from interface:LifecycleCheck whether this component is currently running.In the case of a container, this will return
trueonly if all components that apply are currently running. -
getPhase
public int getPhase()Description copied from interface:SmartLifecycleReturn the phase that this lifecycle object is supposed to run in.The default implementation returns
SmartLifecycle.DEFAULT_PHASEin order to letstop()callbacks execute before regularLifecycleimplementations.- Specified by:
getPhasein interfacePhased- Specified by:
getPhasein interfaceSmartLifecycle- See Also:
-