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

Always retry connections to NATS #69

Merged
merged 1 commit into from
Apr 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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