Class ReactorClientHttpConnector

java.lang.Object
org.springframework.http.client.reactive.ReactorClientHttpConnector
All Implemented Interfaces:
Lifecycle, Phased, SmartLifecycle, ClientHttpConnector

public class ReactorClientHttpConnector extends Object implements ClientHttpConnector, 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, Juergen Hoeller
See Also:
  • HttpClient
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final io.netty.util.AttributeKey<Map<String,Object>>
    Channel attribute key under which WebClient request attributes are stored as a Map.

    Fields inherited from interface org.springframework.context.SmartLifecycle

    DEFAULT_PHASE
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor.
    ReactorClientHttpConnector(ReactorResourceFactory resourceFactory, Function<reactor.netty.http.client.HttpClient,reactor.netty.http.client.HttpClient> mapper)
    Constructor with externally managed Reactor Netty resources, including LoopResources for event loop threads, and ConnectionProvider for the connection pool.
    ReactorClientHttpConnector(reactor.netty.http.client.HttpClient httpClient)
    Constructor with a pre-configured HttpClient instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    reactor.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 given HttpMethod and URI and apply the given requestCallback when the HTTP request of the underlying API can be initialized and written to.
    int
    Return the phase that this lifecycle object is supposed to run in.
    boolean
    Check whether this component is currently running.
    void
    Start this component.
    void
    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
  • Field Details

    • ATTRIBUTES_KEY

      public static final io.netty.util.AttributeKey<Map<String,Object>> ATTRIBUTES_KEY
      Channel attribute key under which WebClient request attributes are stored as a Map.
      Since:
      6.2
  • Constructor Details

    • ReactorClientHttpConnector

      public ReactorClientHttpConnector()
      Default constructor. Initializes HttpClient via:
      HttpClient.create().compress(true)
    • ReactorClientHttpConnector

      public ReactorClientHttpConnector(reactor.netty.http.client.HttpClient httpClient)
      Constructor with a pre-configured HttpClient instance.
      Parameters:
      httpClient - the client to use
      Since:
      5.1
    • ReactorClientHttpConnector

      public ReactorClientHttpConnector(ReactorResourceFactory resourceFactory, Function<reactor.netty.http.client.HttpClient,reactor.netty.http.client.HttpClient> mapper)
      Constructor with externally managed Reactor Netty resources, including LoopResources for event loop threads, and ConnectionProvider 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 a ReactorResourceFactory bean with globalResources=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 from
      mapper - a mapper for further initialization of the created client
      Since:
      5.1
  • Method Details