notification queue server for @gwen.works/churros
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(nats): try reconnecting if the consumer subscription becomes invalid

see https://github.com/nats-io/nats.go/issues/1033
might be
https://github.com/golang/go/issues/15442#issuecomment-214965471

will try https://stackoverflow.com/a/45921617 if the issue persists

+17 -4
+17 -4
server/main.go
··· 146 146 default: 147 147 // Fetch messages in batches 148 148 msgs, err := sub.Fetch(10, nats.MaxWait(5*time.Second)) 149 - if err != nil && err != nats.ErrTimeout { 150 - ll.ErrorDisplay("Could not fetch messages", err) 151 - time.Sleep(2 * time.Second) // Wait before retrying 152 - continue 149 + if err != nil { 150 + if err == nats.ErrTimeout { 151 + ll.WarnDisplay("Timed out fetching messages", err) 152 + } else if err == nats.ErrBadSubscription { 153 + ll.WarnDisplay("Subscription is not valid anymore, trying to reconnect to consumer", err) 154 + sub, err := js.PullSubscribe(notella.SubjectName, "NotellaConsumer") 155 + if err != nil { 156 + ll.ErrorDisplay("could not start consumer", err) 157 + return 158 + } 159 + continue 160 + 161 + } else { 162 + ll.ErrorDisplay("Could not fetch messages", err) 163 + time.Sleep(2 * time.Second) // Wait before retrying 164 + continue 165 + } 153 166 } 154 167 155 168 // Process each message