Skip to content

Commit

Permalink
Fix NATS plug-ins reconnection logic (#1955)
Browse files Browse the repository at this point in the history
* NATS output plug-in now retries to reconnect forever after a lost connection.

* NATS input plug-in now retries to reconnect forever after a lost connection.

* Fixes #1953
  • Loading branch information
pires authored and sparrc committed Oct 26, 2016
1 parent b1a97e3 commit 522658b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ continue sending logs to /var/log/telegraf/telegraf.log.

### Bugfixes

- [#1955](https://github.com/influxdata/telegraf/issues/1955): Fix NATS plug-ins reconnection logic.
- [#1926](https://github.com/influxdata/telegraf/issues/1926): Fix toml unmarshal panic in Duration objects.
- [#1746](https://github.com/influxdata/telegraf/issues/1746): Fix handling of non-string values for JSON keys listed in tag_keys.
- [#1628](https://github.com/influxdata/telegraf/issues/1628): Fix mongodb input panic on version 2.2.
Expand Down
7 changes: 7 additions & 0 deletions plugins/inputs/nats_consumer/nats_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,15 @@ func (n *natsConsumer) Start(acc telegraf.Accumulator) error {

var connectErr error

// set default NATS connection options
opts := nats.DefaultOptions

// override max reconnection tries
opts.MaxReconnect = -1

// override servers if any were specified
opts.Servers = n.Servers

opts.Secure = n.Secure

if n.Conn == nil || n.Conn.IsClosed() {
Expand Down
11 changes: 10 additions & 1 deletion plugins/outputs/nats/nats.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,23 @@ func (n *NATS) SetSerializer(serializer serializers.Serializer) {

func (n *NATS) Connect() error {
var err error
// set NATS connection options

// set default NATS connection options
opts := nats_client.DefaultOptions

// override max reconnection tries
opts.MaxReconnect = -1

// override servers, if any were specified
opts.Servers = n.Servers

// override authentication, if any was specified
if n.Username != "" {
opts.User = n.Username
opts.Password = n.Password
}

// override TLS, if it was specified
tlsConfig, err := internal.GetTLSConfig(
n.SSLCert, n.SSLKey, n.SSLCA, n.InsecureSkipVerify)
if err != nil {
Expand Down

0 comments on commit 522658b

Please sign in to comment.