Class ReactorNettyClientRequestFactory
- 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.1
- Author:
- Arjen Poutsma, Sebastien Deleuze
-
Field Summary
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE
-
Constructor Summary
ConstructorDescriptionCreate a new instance of theReactorNettyClientRequestFactory
with a defaultHttpClient
that has compression enabled.ReactorNettyClientRequestFactory
(ReactorResourceFactory resourceFactory, Function<reactor.netty.http.client.HttpClient, reactor.netty.http.client.HttpClient> mapper) Constructor with externally managed Reactor Netty resources, includingLoopResources
for event loop threads, andConnectionProvider
for the connection pool.ReactorNettyClientRequestFactory
(reactor.netty.http.client.HttpClient httpClient) Create a new instance of theReactorNettyClientRequestFactory
based on the givenHttpClient
. -
Method Summary
Modifier and TypeMethodDescriptioncreateRequest
(URI uri, HttpMethod httpMethod) Create a newClientHttpRequest
for the specified URI and HTTP method.int
getPhase()
Return the phase that this lifecycle object is supposed to run in.boolean
Check whether this component is currently running.void
setConnectTimeout
(int connectTimeout) Set the underlying connect timeout in milliseconds.void
setConnectTimeout
(Duration connectTimeout) Set the underlying connect timeout in milliseconds.void
setExchangeTimeout
(long exchangeTimeout) Set the timeout for the HTTP exchange in milliseconds.void
setExchangeTimeout
(Duration exchangeTimeout) Set the timeout for the HTTP exchange.void
setReadTimeout
(long readTimeout) Set the underlying read timeout in milliseconds.void
setReadTimeout
(Duration readTimeout) Set the underlying read timeout asDuration
.void
start()
Start this component.void
stop()
Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.context.SmartLifecycle
isAutoStartup, stop
-
Constructor Details
-
ReactorNettyClientRequestFactory
public ReactorNettyClientRequestFactory()Create a new instance of theReactorNettyClientRequestFactory
with a defaultHttpClient
that has compression enabled. -
ReactorNettyClientRequestFactory
public ReactorNettyClientRequestFactory(reactor.netty.http.client.HttpClient httpClient) Create a new instance of theReactorNettyClientRequestFactory
based on the givenHttpClient
.- Parameters:
httpClient
- the client to base on
-
ReactorNettyClientRequestFactory
public ReactorNettyClientRequestFactory(ReactorResourceFactory resourceFactory, Function<reactor.netty.http.client.HttpClient, reactor.netty.http.client.HttpClient> mapper) Constructor with externally managed Reactor Netty resources, includingLoopResources
for event loop threads, andConnectionProvider
for the connection pool.This constructor should be used only when you don't want the client to participate in the Reactor Netty global resources. By default the client participates in the Reactor Netty global resources held in
HttpResources
, which is recommended since fixed, shared resources are favored for event loop concurrency. However, consider declaring aReactorResourceFactory
bean withglobalResources=true
in order to ensure the Reactor Netty global resources are shut down when the Spring ApplicationContext is stopped or closed and restarted properly when the Spring ApplicationContext is (with JVM Checkpoint Restore for example).- Parameters:
resourceFactory
- the resource factory to obtain the resources frommapper
- a mapper for further initialization of the created client
-
-
Method Details
-
setConnectTimeout
public void setConnectTimeout(int connectTimeout) Set the underlying connect timeout in milliseconds. A value of 0 specifies an infinite timeout.Default is 30 seconds.
- See Also:
-
Transport.option(ChannelOption, Object)
ChannelOption.CONNECT_TIMEOUT_MILLIS
-
setConnectTimeout
Set the underlying connect timeout in milliseconds. A value of 0 specifies an infinite timeout.Default is 30 seconds.
- See Also:
-
Transport.option(ChannelOption, Object)
ChannelOption.CONNECT_TIMEOUT_MILLIS
-
setReadTimeout
public void setReadTimeout(long readTimeout) Set the underlying read timeout in milliseconds.Default is 10 seconds.
-
setReadTimeout
Set the underlying read timeout asDuration
.Default is 10 seconds.
-
setExchangeTimeout
public void setExchangeTimeout(long exchangeTimeout) Set the timeout for the HTTP exchange in milliseconds.Default is 5 seconds.
-
setExchangeTimeout
Set the timeout for the HTTP exchange.Default is 5 seconds.
-
createRequest
Description copied from interface:ClientHttpRequestFactory
Create a newClientHttpRequest
for the specified URI and HTTP method.The returned request can be written to, and then executed by calling
ClientHttpRequest.execute()
.- Specified by:
createRequest
in 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:Lifecycle
Start this component.Should not throw an exception if the component is already running.
In the case of a container, this will propagate the start signal to all components that apply.
-
stop
public void stop()Description copied from interface:Lifecycle
Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method. Consider implementingSmartLifecycle
and itsstop(Runnable)
variant when asynchronous stop behavior is necessary.Note that this stop notification is not guaranteed to come before destruction: On regular shutdown,
Lifecycle
beans 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:Lifecycle
Check whether this component is currently running.In the case of a container, this will return
true
only if all components that apply are currently running. -
getPhase
public int getPhase()Description copied from interface:SmartLifecycle
Return the phase that this lifecycle object is supposed to run in.The default implementation returns
SmartLifecycle.DEFAULT_PHASE
in order to letstop()
callbacks execute before regularLifecycle
implementations.- Specified by:
getPhase
in interfacePhased
- Specified by:
getPhase
in interfaceSmartLifecycle
- See Also:
-