Top Description Inners Fields Constructors Methods
org.springframework.messaging.tcp.reactor

public Class ReactorNettyTcpClient<P>

extends Object
implements TcpOperations<P>
Class Inheritance
All Implemented Interfaces
org.springframework.messaging.tcp.TcpOperations
Type Parameters
<P>
the type of payload for in and outbound messages
Imports
java.time.Duration, java.util.Collection, .List, java.util.concurrent.CompletableFuture, java.util.function.BiFunction, .Function, io.netty.buffer.ByteBuf, io.netty.channel.ChannelHandlerContext, io.netty.channel.group.ChannelGroup, .DefaultChannelGroup, io.netty.handler.codec.ByteToMessageDecoder, io.netty.util.concurrent.ImmediateEventExecutor, org.apache.commons.logging.Log, .LogFactory, org.reactivestreams.Publisher, reactor.core.publisher.Mono, .Sinks, reactor.core.scheduler.Scheduler, .Schedulers, reactor.netty.Connection, .FutureMono, .NettyInbound, .NettyOutbound, reactor.netty.resources.ConnectionProvider, .LoopResources, reactor.netty.tcp.TcpClient, reactor.util.retry.Retry, org.springframework.lang.Nullable, org.springframework.messaging.Message, org.springframework.messaging.tcp.ReconnectStrategy, .TcpConnection, .TcpConnectionHandler, .TcpOperations, org.springframework.util.Assert

Reactor Netty based implementation of TcpOperations.
Authors
Rossen Stoyanchev, Stephane Maldini
Since
5.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private static class

Field Summary

Modifier and TypeField and Description
private final ChannelGroup
private final ReactorNettyCodec<P>
private Log
private final LoopResources
private final ConnectionProvider
private static final int
private final Scheduler
private volatile boolean
private final TcpClient

Constructor Summary

AccessConstructor and Description
public
ReactorNettyTcpClient(String
the host to connect to
host
,
int
the port to connect to
port
,
ReactorNettyCodec<P>
for encoding and decoding the input/output byte streams
codec
)

Simple constructor with the host and port to use to connect to.

public
ReactorNettyTcpClient(Function<TcpClient, TcpClient>
the configurer function
clientConfigurer
,
ReactorNettyCodec<P>
for encoding and decoding the input/output byte streams
codec
)

A variant of ReactorNettyTcpClient(String, int, ReactorNettyCodec) that still manages the lifecycle of the TcpClient and underlying resources, but allows for direct configuration of other properties of the client through a Function<TcpClient, TcpClient>.

public
ReactorNettyTcpClient(TcpClient
the TcpClient instance to use
tcpClient
,
ReactorNettyCodec<P>
for encoding and decoding the input/output byte streams
codec
)

Constructor with an externally created TcpClient instance whose lifecycle is expected to be managed externally.

Method Summary

Modifier and TypeMethod and Description
public CompletableFuture<Void>
connectAsync(TcpConnectionHandler<P>
a handler to manage the connection
handler
)

Implements org.springframework.messaging.tcp.TcpOperations.connectAsync.

Open a new connection.
public CompletableFuture<Void>
connectAsync(TcpConnectionHandler<P>
a handler to manage the connection
handler
,
ReconnectStrategy
a strategy for reconnecting
strategy
)

Implements org.springframework.messaging.tcp.TcpOperations.connectAsync.

Open a new connection and a strategy for reconnecting if the connection fails.
protected TcpClient

Returns:

the same handler or an updated instance
extendTcpClient
(TcpClient
the candidate TcpClient
tcpClient
,
TcpConnectionHandler<P>
the handler for the TCP connection
handler
)

Provides an opportunity to initialize the TcpClient for the given TcpConnectionHandler which may implement sub-interfaces such as org.springframework.messaging.simp.stomp.StompTcpConnectionHandler that expose further information.

public Log
getLogger()

Return the currently configured Logger.

private CompletableFuture<Void>
private Publisher<? extends Long>
reconnect(Integer attempt, ReconnectStrategy reconnectStrategy)

public void
setLogger(Log
the logger to use
logger
)

Set an alternative logger to use than the one based on the class name.

public CompletableFuture<Void>
shutdownAsync()

Implements org.springframework.messaging.tcp.TcpOperations.shutdownAsync.

Shut down and close any open connections.
private Mono<Void>
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

channelGroupback to summary
private final ChannelGroup channelGroup
Annotations
@Nullable
codecback to summary
private final ReactorNettyCodec<P> codec
loggerback to summary
private Log logger
loopResourcesback to summary
private final LoopResources loopResources
Annotations
@Nullable
poolResourcesback to summary
private final ConnectionProvider poolResources
Annotations
@Nullable
PUBLISH_ON_BUFFER_SIZEback to summary
private static final int PUBLISH_ON_BUFFER_SIZE
schedulerback to summary
private final Scheduler scheduler
stoppingback to summary
private volatile boolean stopping
tcpClientback to summary
private final TcpClient tcpClient

Constructor Detail

ReactorNettyTcpClientback to summary
public ReactorNettyTcpClient(String host, int port, ReactorNettyCodec<P> codec)

Simple constructor with the host and port to use to connect to.

This constructor manages the lifecycle of the TcpClient and underlying resources such as ConnectionProvider, LoopResources, and ChannelGroup.

For full control over the initialization and lifecycle of the TcpClient, use ReactorNettyTcpClient(TcpClient, ReactorNettyCodec).

Parameters
host:String

the host to connect to

port:int

the port to connect to

codec:ReactorNettyCodec<P>

for encoding and decoding the input/output byte streams

See Also
org.springframework.messaging.simp.stomp.StompReactorNettyCodec
ReactorNettyTcpClientback to summary
public ReactorNettyTcpClient(Function<TcpClient, TcpClient> clientConfigurer, ReactorNettyCodec<P> codec)

A variant of ReactorNettyTcpClient(String, int, ReactorNettyCodec) that still manages the lifecycle of the TcpClient and underlying resources, but allows for direct configuration of other properties of the client through a Function<TcpClient, TcpClient>.

Parameters
clientConfigurer:Function<TcpClient, TcpClient>

the configurer function

codec:ReactorNettyCodec<P>

for encoding and decoding the input/output byte streams

Since
5.1.3
See Also
org.springframework.messaging.simp.stomp.StompReactorNettyCodec
ReactorNettyTcpClientback to summary
public ReactorNettyTcpClient(TcpClient tcpClient, ReactorNettyCodec<P> codec)

Constructor with an externally created TcpClient instance whose lifecycle is expected to be managed externally.

Parameters
tcpClient:TcpClient

the TcpClient instance to use

codec:ReactorNettyCodec<P>

for encoding and decoding the input/output byte streams

See Also
org.springframework.messaging.simp.stomp.StompReactorNettyCodec

Method Detail

connectAsyncback to summary
public CompletableFuture<Void> connectAsync(TcpConnectionHandler<P> handler)

Implements org.springframework.messaging.tcp.TcpOperations.connectAsync.

Doc from org.springframework.messaging.tcp.TcpOperations.connectAsync.

Open a new connection.

Parameters
handler:TcpConnectionHandler<P>

a handler to manage the connection

Returns:CompletableFuture<Void>

a CompletableFuture that can be used to determine when and if the connection is successfully established

Annotations
@Override
connectAsyncback to summary
public CompletableFuture<Void> connectAsync(TcpConnectionHandler<P> handler, ReconnectStrategy strategy)

Implements org.springframework.messaging.tcp.TcpOperations.connectAsync.

Doc from org.springframework.messaging.tcp.TcpOperations.connectAsync.

Open a new connection and a strategy for reconnecting if the connection fails.

Parameters
handler:TcpConnectionHandler<P>

a handler to manage the connection

strategy:ReconnectStrategy

a strategy for reconnecting

Returns:CompletableFuture<Void>

a CompletableFuture that can be used to determine when and if the initial connection is successfully established

Annotations
@Override
extendTcpClientback to summary
protected TcpClient extendTcpClient(TcpClient tcpClient, TcpConnectionHandler<P> handler)

Provides an opportunity to initialize the TcpClient for the given TcpConnectionHandler which may implement sub-interfaces such as org.springframework.messaging.simp.stomp.StompTcpConnectionHandler that expose further information.

Parameters
tcpClient:TcpClient

the candidate TcpClient

handler:TcpConnectionHandler<P>

the handler for the TCP connection

Returns:TcpClient

the same handler or an updated instance

getLoggerback to summary
public Log getLogger()

Return the currently configured Logger.

Since
5.1
handleShuttingDownConnectFailureback to summary
private CompletableFuture<Void> handleShuttingDownConnectFailure(TcpConnectionHandler<P> handler)
reconnectback to summary
private Publisher<? extends Long> reconnect(Integer attempt, ReconnectStrategy reconnectStrategy)
setLoggerback to summary
public void setLogger(Log logger)

Set an alternative logger to use than the one based on the class name.

Parameters
logger:Log

the logger to use

Since
5.1
shutdownAsyncback to summary
public CompletableFuture<Void> shutdownAsync()

Implements org.springframework.messaging.tcp.TcpOperations.shutdownAsync.

Doc from org.springframework.messaging.tcp.TcpOperations.shutdownAsync.

Shut down and close any open connections.

Returns:CompletableFuture<Void>

a CompletableFuture that can be used to determine when and if the connection is successfully closed

Annotations
@Override
stopSchedulerback to summary
private Mono<Void> stopScheduler()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
org.springframework.messaging.tcp.reactor back to summary

private Class ReactorNettyTcpClient.ReactorNettyHandler

extends Object
implements BiFunction<NettyInbound, NettyOutbound, Publisher<Void>>
Class Inheritance
  • java.lang.Object
  • org.springframework.messaging.tcp.reactor.ReactorNettyTcpClient.ReactorNettyHandler
All Implemented Interfaces
java.util.function.BiFunction

Field Summary

Modifier and TypeField and Description
private final TcpConnectionHandler<P>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public Publisher<Void>
apply(NettyInbound
the first function argument
inbound
,
NettyOutbound
the second function argument
outbound
)

Implements java.util.function.BiFunction.apply.

Applies this function to the given arguments.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

connectionHandlerback to summary
private final TcpConnectionHandler<P> connectionHandler

Constructor Detail

ReactorNettyHandlerback to summary
pack-priv ReactorNettyHandler(TcpConnectionHandler<P> handler)

Method Detail

applyback to summary
public Publisher<Void> apply(NettyInbound inbound, NettyOutbound outbound)

Implements java.util.function.BiFunction.apply.

Doc from java.util.function.BiFunction.apply.

Applies this function to the given arguments.

Parameters
inbound:NettyInbound

the first function argument

outbound:NettyOutbound

the second function argument

Returns:Publisher<Void>

the function result

Annotations
@Override
@SuppressWarnings:unchecked
org.springframework.messaging.tcp.reactor back to summary

private Class ReactorNettyTcpClient.StompMessageDecoder<P>

extends ByteToMessageDecoder
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final ReactorNettyCodec<P>
Inherited from io.netty.handler.codec.ByteToMessageDecoder:
COMPOSITE_CUMULATORMERGE_CUMULATOR

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected void
decode(ChannelHandlerContext ctx, ByteBuf
the ByteBuf from which to read data
in
,
List<Object>
the List to which decoded messages should be added
out
)

Implements abstract io.netty.handler.codec.ByteToMessageDecoder.decode.

Decode the from one ByteBuf to an other.
Inherited from io.netty.handler.codec.ByteToMessageDecoder:
actualReadableBytescallDecodechannelInactivechannelReadchannelReadCompletedecodeLastdiscardSomeReadByteshandlerRemovedhandlerRemoved0internalBufferisSingleDecodesetCumulatorsetDiscardAfterReadssetSingleDecodeuserEventTriggered

Field Detail

codecback to summary
private final ReactorNettyCodec<P> codec

Constructor Detail

StompMessageDecoderback to summary
pack-priv StompMessageDecoder(ReactorNettyCodec<P> codec)

Method Detail

decodeback to summary
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out)

Implements abstract io.netty.handler.codec.ByteToMessageDecoder.decode.

Doc from io.netty.handler.codec.ByteToMessageDecoder.decode.

Decode the from one ByteBuf to an other. This method will be called till either the input ByteBuf has nothing to read when return from this method or till nothing was read from the input ByteBuf.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext which this ByteToMessageDecoder belongs to

in:ByteBuf

the ByteBuf from which to read data

out:List<Object>

the List to which decoded messages should be added

Annotations
@Override