The replicator uses a single configuration file passed on the command line or environment variable. Configuration is organized into a root section and several blocks.
The configuration file format matches the NATS server and supports file includes of the form:
include "./includes/connectors.conf"
All properties are semi-case-insensitive. If you use the case in the doc it is ok, or use all lower case. Also, multi-word properties have two forms, to match your style better.
To set the configuration on the command line, use:
% nats-replicator -c <path to config file>
To set the configuration file using an environment variable, export NATS_REPLICATOR_CONFIG
with the path to the configuration.
The root section:
reconnectinterval: 5000,
can currently contain settings for:
reconnectinterval
orreconnect_interval
- this value, in milliseconds, is the time used in between reconnection attempts for a connector when it fails. For example, if a connector loses access to NATS, the replicator will try to restart it everyreconnectinterval
milliseconds.
NATS, streaming and HTTP configurations all take an optional TLS setting. The TLS configuration takes three possible settings:
root
- file path to a CA root certificate store, used for NATS connectionscert
- file path to a server certificate, used for HTTPS monitoring and optionally for client side certificates with NATSkey
- key for the certificate store specified in cert
Logging is configured in a manner similar to the nats-server:
logging: {
time: true,
debug: false,
trace: false,
colors: true,
pid: false,
}
These properties are configured for:
time
- include the time in logging statementsdebug
- include debug loggingtrace
- include verbose, or trace, loggingcolors
- colorize the logging statementspid
- include the process id in logging statements
The monitoring section:
monitoring: {
httpsport: -1,
tls: {
cert: /a/server-cert.pem,
key: /a/server-key.pem,
}
}
Is used to configure an HTTP or HTTPS port, as well as TLS settings when HTTPS is used.
httphost
orhttp_host
- the network interface to publish monitoring on, valid for HTTP or HTTPS. An empty value will tell the replicator to use all available network interfaces.httpport
orhttp_port
- the port for HTTP monitoring, no TLS configuration is expected, a value of -1 will tell the replicator to use an ephemeral port, the port will be logged on startup.
2019/03/20 12:06:38.027822 [INF] starting http monitor on :59744
httpsport
orhttps_port
- the port for HTTPS monitoring, a TLS configuration is expected, a value of -1 will tell the server to use an ephemeral port, the port will be logged on startup.tls
- a TLS configuration.
The httpport
and httpsport
settings are mutually exclusive, if both are set to a non-zero value the replicator will not start.
The replicator can make multiple connections to NATS. Each connection has a name so that connectors can refer to it. Streaming connections also use the name of a NATS connection to refer to it. Configuration is through the nats
section of the config file, which defines an array of connection parameters:
nats: [
{
Name: "connection_one",
Servers: ["localhost:4222"],
ConnectTimeout: 5000,
MaxReconnects: 5,
ReconnectWait: 5000,
}
]
NATS can be configured with the following properties:
name
- the unique name used to refer to this configuration/connectionservers
- an array of server URLSconnecttimeout
orconnect_timeout
- the time, in milliseconds, to wait before failing to connect to the NATS serverreconnectwait
orreconnect_wait
- the time, in milliseconds, to wait between reconnect attemptsmaxreconnects
ormax_reconnects
- the maximum number of reconnects to try before exiting the replicator with an error.noecho
orno_echo
- don't echo messages back from this clientnorandom
orno_random
- don't randomize servers in the connect listtls
- (optional) TLS configuration. If the NATS server uses unverified TLS with a valid certificate, this setting isn't required.usercredentials
oruser_credentials
- (optional) the path to a credentials file for connecting to NATs.
The replicator can make multiple connections to streaming servers. Each streaming connection must refer to a NATS connection by name. This reduces the configuration clutter by keeping NATS parameters in the NATS section. Configuration is through the stan
section of the config file, which defines an array:
stan: [
{
Name: "stan_one",
NATSConnection: "connection_one",
ClusterID: "test-cluster"
ClientID: "replicator_one"
}
]
Multiple streaming connections could use the same NATS connection.
NATS streaming can be configured with the following properties:
name
- the unique name used to refer to this configuration/connectionnatsconnection
ornats_connection
- the unique name of the nats connection to use for this streaming connectionclusterid
orcluster_id
- the cluster id for the NATS streaming server.clientid
orclient_id
- the client id for the connection.pubackwait
orpub_ack_wait
- the time, in milliseconds, to wait before a publish fails due to a timeout.discoverprefix
ordiscover_prefix
- the discover prefix for the streaming server.maxpubacksinflight
ormax_pubacks_inflight
- maximum pub ACK messages that can be in flight for this connection, defaults to streaming default.connectwait
orconnect_wait
- the time, in milliseconds, to wait before failing to connect to the streaming server.
The final piece of the replicator configuration is the connect
section. Connect specifies an array of connector configurations. All connector configs use the same format, relying on optional settings to determine what the do.
connect: [
{
type: NATSToNATS,
id: "alpha",
IncomingSubject: "in",
IncomingConnection: "connection_one",
OutgoingSubject: "out",
OutgoingConnection: "connection_one",
},
],
The most important property in the connector configuration is the type
. The type determines which kind of connector is instantiated. Available, uni-directional, types include:
NATSToNATS
- a subject to subject connectorNATSToStan
- a subject to streaming connectorStanToNATS
- a streaming to subject connectorStanToStan
- a streaming to streaming connector
These types are case insensitive, so "natstonats" is the same as "NATSToNATS".
All connectors can have an optional id, which is used in monitoring:
id
- (optional) user defined id that will tag the connection in monitoring JSON.
All connectors require a configuration for the connection to use:
incomingconnection
orincoming_connection
- the name of a NATS or streaming connection to subscribe tooutgoingconnection
oroutgoing_connection
- the name of a NATS or streaming connection to publish to
For NATS connections, specify:
incomingsubject
orincoming_subject
- the subject to subscribe to, depending on the connections direction.incomingqueuename
orincoming_queue_name
- the queue group to use in subscriptions, this is optional but useful for load balancing.outgoingsubject
oroutgoing_subject
- the subject to publish to, depending on the connections direction.
Keep in mind that NATS queue groups do not guarantee ordering, since the queue subscribers can be on different nats-servers in a cluster. So if you have to replicators running with connectors on the same NATS queue/subject pair and have a high message rate you may get messages to the receiver "out of order." Also, note that there is no outgoing queue.
These settings are directional depending so a NATSToStan
connector would use an incomingsubject
while a StanToNATS
connector would use an outgoingsubject
. Connectors ignore settings they don't need.
For streaming connections, the channel setting is required (directionality dependent), the others are optional:
incomingchannel
orincoming_channel
- the streaming channel to subscribe to.outgoingchannel
oroutgoing_channel
- the streaming channel to publish to.incomingdurablename
orincoming_durable_name
- (optional) durable name for the streaming subscription (if appropriate.)incomingstartatsequence
orincoming_startat_sequence
- (optional) start position, use -1 for start with last received, 0 for deliver all available (the default.)incomingstartattime
orincoming_startat_time
- (optional) the start position as a time, in Unix seconds since the epoch, mutually exclusive withstartatsequence
.
For example, a simple configuration may look something like:
reconnectinterval: 5000,
logging: {
Time: true,
Debug: true,
Trace: false,
Colors: true,
PID: false,
},
monitoring: {
httpport: 9090,
}
nats: [
{
Name: "nats",
Servers: ["localhost:4222"],
ConnectTimeout: 5000,
MaxReconnects: 5,
ReconnectWait: 5000,
}
]
connect: [
{
type: NATSToNATS,
id: "alpha",
IncomingSubject: "in",
IncomingConnection: "nats",
OutgoingSubject: "out",
OutgoingConnection: "nats",
},
],