Package org.springframework.http.client

# Class ReactorClientHttpRequestFactory

java.lang.Object
org.springframework.http.client.ReactorClientHttpRequestFactory

All Implemented Interfaces:
  `org.springframework.context.Lifecycle`, `org.springframework.context.Phased`, `org.springframework.context.SmartLifecycle`, `ClientHttpRequestFactory`

Direct Known Subclasses:
  `ReactorNettyClientRequestFactory`

public class ReactorClientHttpRequestFactory extends Object implements ClientHttpRequestFactory, org.springframework.context.SmartLifecycle
Reactor-Netty implementation of `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 org.springframework.context.SmartLifecycle

`DEFAULT_PHASE`

## Constructor Summary

Constructors
Constructor
Description
`ReactorClientHttpRequestFactory()`
Constructor with default client, created via `HttpClient.create()`, and with `compression` enabled.
`ReactorClientHttpRequestFactory(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 connection pooling.
`ReactorClientHttpRequestFactory(reactor.netty.http.client.HttpClient client)`
Constructor with a given `HttpClient` instance.

## Method Summary

Modifier and Type
Method
Description
`ClientHttpRequest`
`createRequest(URI uri, HttpMethod httpMethod)`
Create a new `ClientHttpRequest` for the specified URI and HTTP method.
`int`
`getPhase()`
`boolean`
`isRunning()`
`void`
`setConnectTimeout(int connectTimeout)`
Set the connect timeout value on the underlying client.
`void`
`setConnectTimeout(Duration connectTimeout)`
Variant of `setConnectTimeout(int)` with a `Duration` value.
`void`
`setExchangeTimeout(long exchangeTimeout)`
Deprecated, for removal: This API element is subject to removal in a future version.
as of 6.2 and no longer set by default (previously 5 seconds) in favor of using Reactor Netty HttpClient timeout configuration.
`void`
`setExchangeTimeout(Duration exchangeTimeout)`
Deprecated, for removal: This API element is subject to removal in a future version.
as of 6.2 and no longer set by default (previously 5 seconds) in favor of using Reactor Netty HttpClient timeout configuration.
`void`
`setExecutor(Executor executor)`
Set the `Executor` to use for performing blocking I/O operations.
`void`
`setReadTimeout(long readTimeout)`
Variant of `setReadTimeout(Duration)` with a long value.
`void`
`setReadTimeout(Duration timeout)`
Set the read timeout value on the underlying client.
`void`
`start()`
`void`
`stop()`

### 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

### ReactorClientHttpRequestFactory

public ReactorClientHttpRequestFactory()
Constructor with default client, created via `HttpClient.create()`, and with `compression` enabled.

### ReactorClientHttpRequestFactory

public ReactorClientHttpRequestFactory(reactor.netty.http.client.HttpClient client)
Constructor with a given `HttpClient` instance.

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, including `LoopResources` for event loop threads, and `ConnectionProvider` for 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 a `ReactorResourceFactory` bean. 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 from
  `mapper` - for further initialization of the client

## Method Details

### setExecutor

public void setExecutor(Executor executor)
Set the `Executor` to 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 value on the underlying client. Effectively, a shortcut for `httpClient.option(CONNECT_TIMEOUT_MILLIS, timeout)`.

By default, set to 30 seconds.

Parameters:
  `connectTimeout` - the timeout value in millis; use 0 to never time out.
See Also:
  - `Transport.option(ChannelOption, Object)`
  - `ChannelOption.CONNECT_TIMEOUT_MILLIS`
  - Connection Timeout

### setConnectTimeout

public void setConnectTimeout(Duration connectTimeout)
Variant of `setConnectTimeout(int)` with a `Duration` value.

### setReadTimeout

public void setReadTimeout(Duration timeout)
Set the read timeout value on the underlying client. Effectively, a shortcut for `HttpClient.responseTimeout(Duration)`.

By default, set to 10 seconds.

Parameters:
  `timeout` - the read timeout value in millis; must be > 0.

### setReadTimeout

public void setReadTimeout(long readTimeout)
Variant of `setReadTimeout(Duration)` with a long value.

### setExchangeTimeout

@Deprecated(since="6.2", forRemoval=true) public void setExchangeTimeout(long exchangeTimeout)
Deprecated, for removal: This API element is subject to removal in a future version.
as of 6.2 and no longer set by default (previously 5 seconds) in favor of using Reactor Netty HttpClient timeout configuration.
Set the timeout for the HTTP exchange in milliseconds.

By default, as of 6.2 this is no longer set.

See Also:
  - `setConnectTimeout(int)`
  - `setReadTimeout(Duration)`
  - Timeout Configuration

### setExchangeTimeout

@Deprecated(since="6.2", forRemoval=true) public void setExchangeTimeout(Duration exchangeTimeout)
Deprecated, for removal: This API element is subject to removal in a future version.
as of 6.2 and no longer set by default (previously 5 seconds) in favor of using Reactor Netty HttpClient timeout configuration.
Variant of `setExchangeTimeout(long)` with a Duration value.

By default, as of 6.2 this is no longer set.

See Also:
  - `setConnectTimeout(int)`
  - `setReadTimeout(Duration)`
  - Timeout Configuration

### createRequest

public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException
Description copied from interface: `ClientHttpRequestFactory`
Create a new `ClientHttpRequest` 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 interface `ClientHttpRequestFactory`
Parameters:
  `uri` - the URI to create a request for
  `httpMethod` - the HTTP method to execute
Returns:
  the created request
Throws:
  `IOException` - in case of I/O errors

### start

public void start()

Specified by:
  `start` in interface `org.springframework.context.Lifecycle`

### stop

public void stop()

Specified by:
  `stop` in interface `org.springframework.context.Lifecycle`

### isRunning

public boolean isRunning()

Specified by:
  `isRunning` in interface `org.springframework.context.Lifecycle`

### getPhase

public int getPhase()

Specified by:
  `getPhase` in interface `org.springframework.context.Phased`
Specified by:
  `getPhase` in interface `org.springframework.context.SmartLifecycle`