作者 唐旭辉

更新

@@ -41,7 +41,7 @@ func main() { @@ -41,7 +41,7 @@ func main() {
41 select { 41 select {
42 case <-sigs: 42 case <-sigs:
43 cancel() 43 cancel()
44 - wg.wait() 44 + wg.Wait()
45 return 45 return
46 default: 46 default:
47 } 47 }
@@ -3,6 +3,7 @@ package consumer @@ -3,6 +3,7 @@ package consumer
3 import ( 3 import (
4 "context" 4 "context"
5 "errors" 5 "errors"
  6 + "time"
6 7
7 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/port/consumer/configs" 8 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/port/consumer/configs"
8 9
@@ -110,12 +111,15 @@ func (r *Runer) Start(ctx context.Context) { @@ -110,12 +111,15 @@ func (r *Runer) Start(ctx context.Context) {
110 for { 111 for {
111 select { 112 select {
112 case <-ctx.Done(): 113 case <-ctx.Done():
113 - r.consumerGroup.Close()  
114 - logs.Warning("ctx cancel;consumerGroup.Close()") 114 + err := r.consumerGroup.Close()
  115 + logs.Warning("ctx cancel;consumerGroup.Close();err:%s", err)
115 return 116 return
116 default: 117 default:
117 if err := r.consumerGroup.Consume(ctx, r.msgConsumer.topics, r.msgConsumer); err != nil { 118 if err := r.consumerGroup.Consume(ctx, r.msgConsumer.topics, r.msgConsumer); err != nil {
118 logs.Error("consumerGroup err:%s \n", err) 119 logs.Error("consumerGroup err:%s \n", err)
  120 + //等待重试
  121 + timer := time.NewTimer(5 * time.Second)
  122 + <-timer.C
119 } 123 }
120 r.msgConsumer.ready = make(chan struct{}) 124 r.msgConsumer.ready = make(chan struct{})
121 } 125 }