Class ReactorClientHttpConnector
java.lang.Object
org.springframework.http.client.reactive.ReactorClientHttpConnector
- All Implemented Interfaces:
org.springframework.context.Lifecycle
,org.springframework.context.Phased
,org.springframework.context.SmartLifecycle
,ClientHttpConnector
public class ReactorClientHttpConnector
extends Object
implements ClientHttpConnector, org.springframework.context.SmartLifecycle
Reactor-Netty implementation of
ClientHttpConnector
.
This class implements SmartLifecycle
and can be optionally declared
as a Spring-managed bean.
- Since:
- 5.0
- Author:
- Brian Clozel, Rossen Stoyanchev, Sebastien Deleuze
- See Also:
-
HttpClient
-
Field Summary
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE
-
Constructor Summary
ConstructorDescriptionDefault constructor.ReactorClientHttpConnector
(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.ReactorClientHttpConnector
(reactor.netty.http.client.HttpClient httpClient) Constructor with a pre-configuredHttpClient
instance. -
Method Summary
Modifier and TypeMethodDescriptionreactor.core.publisher.Mono<ClientHttpResponse>
connect
(HttpMethod method, URI uri, Function<? super ClientHttpRequest, reactor.core.publisher.Mono<Void>> requestCallback) Connect to the origin server using the givenHttpMethod
andURI
and apply the givenrequestCallback
when the HTTP request of the underlying API can be initialized and written to.int
getPhase()
boolean
boolean
void
start()
void
stop()
final void
-
Constructor Details
-
ReactorClientHttpConnector
public ReactorClientHttpConnector()Default constructor. InitializesHttpClient
via:HttpClient.create().compress()
-
ReactorClientHttpConnector
public ReactorClientHttpConnector(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- Since:
- 5.1
-
ReactorClientHttpConnector
public ReactorClientHttpConnector(reactor.netty.http.client.HttpClient httpClient) Constructor with a pre-configuredHttpClient
instance.- Parameters:
httpClient
- the client to use- Since:
- 5.1
-
-
Method Details
-
connect
public reactor.core.publisher.Mono<ClientHttpResponse> connect(HttpMethod method, URI uri, Function<? super ClientHttpRequest, reactor.core.publisher.Mono<Void>> requestCallback) Description copied from interface:ClientHttpConnector
Connect to the origin server using the givenHttpMethod
andURI
and apply the givenrequestCallback
when the HTTP request of the underlying API can be initialized and written to.- Specified by:
connect
in interfaceClientHttpConnector
- Parameters:
method
- the HTTP request methoduri
- the HTTP request URIrequestCallback
- a function that prepares and writes to the request, returning a publisher that signals when it's done writing. Implementations can return aMono<Void>
by callingReactiveHttpOutputMessage.writeWith(org.reactivestreams.Publisher<? extends org.springframework.core.io.buffer.DataBuffer>)
orReactiveHttpOutputMessage.setComplete()
.- Returns:
- publisher for the
ClientHttpResponse
-
start
public void start()- Specified by:
start
in interfaceorg.springframework.context.Lifecycle
-
stop
public void stop()- Specified by:
stop
in interfaceorg.springframework.context.Lifecycle
-
stop
- Specified by:
stop
in interfaceorg.springframework.context.SmartLifecycle
-
isRunning
public boolean isRunning()- Specified by:
isRunning
in interfaceorg.springframework.context.Lifecycle
-
isAutoStartup
public boolean isAutoStartup()- Specified by:
isAutoStartup
in interfaceorg.springframework.context.SmartLifecycle
-
getPhase
public int getPhase()- Specified by:
getPhase
in interfaceorg.springframework.context.Phased
- Specified by:
getPhase
in interfaceorg.springframework.context.SmartLifecycle
-