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

Commit

Permalink
Merge pull request #69 from mjs/always-retry-nats-connections
Browse files Browse the repository at this point in the history
Always retry connections to NATS
  • Loading branch information
oplehto authored Apr 24, 2018
2 parents f836098 + f30ffb7 commit b2eb25e
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 b2eb25e

Please sign in to comment.