Class ReactorNettyClientRequestFactory
- 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.1
- Author:
- Arjen Poutsma, Sebastien Deleuze
-
Field Summary
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new instance of theReactorNettyClientRequestFactorywith a defaultHttpClientthat 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, includingLoopResourcesfor event loop threads, andConnectionProviderfor the connection pool.ReactorNettyClientRequestFactory(reactor.netty.http.client.HttpClient httpClient) Create a new instance of theReactorNettyClientRequestFactorybased on the givenHttpClient. -
Method Summary
Modifier and TypeMethodDescriptioncreateRequest(URI uri, HttpMethod httpMethod) Create a newClientHttpRequestfor the specified URI and HTTP method.intgetPhase()booleanbooleanvoidsetConnectTimeout(int connectTimeout) Set the underlying connect timeout in milliseconds.voidsetConnectTimeout(Duration connectTimeout) Set the underlying connect timeout in milliseconds.voidsetExchangeTimeout(long exchangeTimeout) Set the timeout for the HTTP exchange in milliseconds.voidsetExchangeTimeout(Duration exchangeTimeout) Set the timeout for the HTTP exchange.voidsetReadTimeout(long readTimeout) Set the underlying read timeout in milliseconds.voidsetReadTimeout(Duration readTimeout) Set the underlying read timeout asDuration.voidstart()voidstop()final void
-
Constructor Details
-
ReactorNettyClientRequestFactory
public ReactorNettyClientRequestFactory()Create a new instance of theReactorNettyClientRequestFactorywith a defaultHttpClientthat has compression enabled. -
ReactorNettyClientRequestFactory
public ReactorNettyClientRequestFactory(reactor.netty.http.client.HttpClient httpClient) Create a new instance of theReactorNettyClientRequestFactorybased 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, includingLoopResourcesfor event loop threads, andConnectionProviderfor 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 aReactorResourceFactorybean withglobalResources=truein 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 30 seconds.
-
setExchangeTimeout
Set the timeout for the HTTP exchange.Default is 30 seconds.
-
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
-
stop
- Specified by:
stopin interfaceorg.springframework.context.SmartLifecycle
-
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceorg.springframework.context.Lifecycle
-
isAutoStartup
public boolean isAutoStartup()- Specified by:
isAutoStartupin interfaceorg.springframework.context.SmartLifecycle
-
getPhase
public int getPhase()- Specified by:
getPhasein interfaceorg.springframework.context.Phased- Specified by:
getPhasein interfaceorg.springframework.context.SmartLifecycle
-