NAME
re-pair(3)
SYNOPSIS
uber simple reconnect logic for tls
or tcp
.
MOTIVATION
The process of reconnecting a client should be smarter than just re-trying the same server repeatedly. A client should attempt to round-robin connection attempts to a series of servers running on different subnets (or at least in different data centers) and exponentially back off from connections that fail.
EXAMPLES
Connect to a server
var restream = ; var options = reconnectTime: 128 // time before attempting to reconnect connectTime: 1024 // max time spent attempting to connect servers: port: 9960 host: '192.0.0.2' port: 9968 host: '187.0.0.1' port: 9020 host: '123.0.0.3' port: 9967 host: '111.1.1.1' var client = restream client client client
API
connect([options])
The options object also accepts the regular options that are accepted by the
tls.connect and
tcp.connect` methods. Method returns an event emitter.
{ protocol: <Object> }
[options] Specify if something other than tcp
should be used.
{ reconnectTime: <Number> }
[options] An optional number to determine how long before attempting the next
reconnection.
Defaults to 3e4
. Note that this number is multiplied by the number of
failures to connect.
{ connectTime: <Number> }
[options] An optional number to determine how long before a simple connection attempt should be timed out.
{ servers: <Object> }
[options] An array that contains a list of servers. Each object in the array should
contain a port
and host
address. When a connection can't be made to a
server, the next server in the array is selected for the reconnect attempt.
{ maxCycles: <Number> }
[options] How many times to cycle though the start list before calling the onFail
method.