This repository has no description
0

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

+5 -3
+5 -3
server/main.go
··· 18 18 19 19 var Version = "DEV" 20 20 21 + var consumerSub *nats.Subscription 22 + 21 23 func main() { 22 24 figure.NewColorFigure("Notella", "", "yellow", true).Print() 23 25 fmt.Printf("%38s\n", fmt.Sprintf("美味しそう〜 v%s", Version)) ··· 101 103 102 104 ll.Log("Starting", "cyan", "consumer [bold]NotellaConsumer[reset]") 103 105 104 - sub, err := js.PullSubscribe(notella.SubjectName, "NotellaConsumer") 106 + consumerSub, err = js.PullSubscribe(notella.SubjectName, "NotellaConsumer") 105 107 if err != nil { 106 108 ll.ErrorDisplay("could not start consumer", err) 107 109 return ··· 145 147 return 146 148 default: 147 149 // Fetch messages in batches 148 - msgs, err := sub.Fetch(10, nats.MaxWait(5*time.Second)) 150 + msgs, err := consumerSub.Fetch(10, nats.MaxWait(5*time.Second)) 149 151 if err != nil { 150 152 if err == nats.ErrTimeout { 151 153 ll.WarnDisplay("Timed out fetching messages", err) 152 154 } else if err == nats.ErrBadSubscription { 153 155 ll.WarnDisplay("Subscription is not valid anymore, trying to reconnect to consumer", err) 154 - sub, err := js.PullSubscribe(notella.SubjectName, "NotellaConsumer") 156 + consumerSub, err = js.PullSubscribe(notella.SubjectName, "NotellaConsumer") 155 157 if err != nil { 156 158 ll.ErrorDisplay("could not start consumer", err) 157 159 return