Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Commit

Permalink
Always retry connections to NATS
Browse files Browse the repository at this point in the history
The NATS connections created by the filter and monitor weren't set to
keep retrying and were using the default reconnection limit of 60.

The listener and writer were using infinite NATS reconnection
attempts but were setting this up in an undocumented way (which may
not always have worked).
  • Loading branch information
mjs committed Apr 24, 2018
1 parent f836098 commit f30ffb7
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 10 deletions.
2 changes: 1 addition & 1 deletion filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func StartFilter(conf *config.Config) (_ *Filter, err error) {
}

func (f *Filter) natsConnect() (natsConn, error) {
nc, err := nats.Connect(f.c.NATSAddress)
nc, err := nats.Connect(f.c.NATSAddress, nats.MaxReconnects(-1))
if err != nil {
return nil, fmt.Errorf("NATS: failed to connect: %v", err)
}
Expand Down
4 changes: 1 addition & 3 deletions listener/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,10 @@ func newListener(c *config.Config) (*Listener, error) {
batchSizeThreshold: c.ListenerBatchBytes - udpMaxDatagramSize,
}

nc, err := nats.Connect(l.c.NATSAddress)
nc, err := nats.Connect(l.c.NATSAddress, nats.MaxReconnects(-1))
if err != nil {
return nil, err
}
// If we disconnect, we want to try reconnecting as many times as we can.
nc.Opts.MaxReconnect = -1
l.nc = nc

return l, nil
Expand Down
2 changes: 1 addition & 1 deletion monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (m *Monitor) Stop() {
}

func (m *Monitor) natsConnect() (*nats.Conn, error) {
nc, err := nats.Connect(m.c.NATSAddress)
nc, err := nats.Connect(m.c.NATSAddress, nats.MaxReconnects(-1))
if err != nil {
return nil, fmt.Errorf("NATS: failed to connect: %v", err)
}
Expand Down
6 changes: 1 addition & 5 deletions writer/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,11 @@ func StartWriter(c *config.Config) (_ *Writer, err error) {
return nil, err
}

w.nc, err = nats.Connect(c.NATSAddress)
w.nc, err = nats.Connect(c.NATSAddress, nats.MaxReconnects(-1))
if err != nil {
return nil, fmt.Errorf("NATS Error: can't connect: %v", err)
}

// if we disconnect, we want to try reconnecting as many times as
// we can
w.nc.Opts.MaxReconnect = -1

http.DefaultTransport.(*http.Transport).MaxIdleConnsPerHost = 100

jobs := make(chan *nats.Msg, 1024)
Expand Down

0 comments on commit f30ffb7

Please sign in to comment.