Invalid NATS connection fix when subscribing to a subject
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Adam Štrauch 2021-12-31 08:09:44 +01:00
parent 55b3376d4c
commit 157e795792
Signed by: cx
GPG Key ID: 018304FFA8988F8D

View File

@ -55,12 +55,10 @@ func (d *Driver) Init() error {
return fmt.Errorf("please initiate LogChannel variable")
}
var nc *nats.Conn
for {
nc, err := nats.Connect(d.NATSUrl)
if err != nil {
log.Println("Can't connect to the NATS server, waiting for 5 seconds before I try it again.")
log.Printf("Can't connect to the NATS server, waiting for 5 seconds before I try it again. (%v)\n", err)
time.Sleep(time.Second * 5)
continue
}
@ -68,9 +66,9 @@ func (d *Driver) Init() error {
break
}
_, err := nc.Subscribe(d.NATSDiscoveryChannel, d.handler)
_, err := d.nc.Subscribe(d.NATSDiscoveryChannel, d.handler)
if err != nil {
return err
return fmt.Errorf("subscribe error: %v", err)
}
return nil