|
@@ -18,6 +18,8 @@ type MessageConsumer struct { |
|
@@ -18,6 +18,8 @@ type MessageConsumer struct { |
18
|
groupId string
|
18
|
groupId string
|
19
|
topics []string
|
19
|
topics []string
|
20
|
topicsHandles map[string]TopicHandle
|
20
|
topicsHandles map[string]TopicHandle
|
|
|
21
|
+ beforeHandles []TopicHandle
|
|
|
22
|
+ afterHandles []TopicHandle
|
21
|
}
|
23
|
}
|
22
|
|
24
|
|
23
|
// func NewMessageConsumer() *MessageConsumer {
|
25
|
// func NewMessageConsumer() *MessageConsumer {
|
|
@@ -58,7 +60,6 @@ func (c *MessageConsumer) ConsumeClaim(groupSession sarama.ConsumerGroupSession, |
|
@@ -58,7 +60,6 @@ func (c *MessageConsumer) ConsumeClaim(groupSession sarama.ConsumerGroupSession, |
58
|
groupSession.MarkMessage(message, "")
|
60
|
groupSession.MarkMessage(message, "")
|
59
|
if topicHandle, err = c.FindTopichandle(groupClaim.Topic()); err != nil {
|
61
|
if topicHandle, err = c.FindTopichandle(groupClaim.Topic()); err != nil {
|
60
|
logs.Error("FindTopichandle err:%s \n", err)
|
62
|
logs.Error("FindTopichandle err:%s \n", err)
|
61
|
-
|
|
|
62
|
continue
|
63
|
continue
|
63
|
}
|
64
|
}
|
64
|
if err = topicHandle(message); err != nil {
|
65
|
if err = topicHandle(message); err != nil {
|
|
@@ -93,6 +94,8 @@ func NewRuner() *Runer { |
|
@@ -93,6 +94,8 @@ func NewRuner() *Runer { |
93
|
groupId: configs.Cfg.ConsumerId,
|
94
|
groupId: configs.Cfg.ConsumerId,
|
94
|
topicsHandles: TopicHandleRouters,
|
95
|
topicsHandles: TopicHandleRouters,
|
95
|
topics: topics,
|
96
|
topics: topics,
|
|
|
97
|
+ beforeHandles: BeforeHandles,
|
|
|
98
|
+ afterHandles: AfterHandles,
|
96
|
},
|
99
|
},
|
97
|
}
|
100
|
}
|
98
|
}
|
101
|
}
|
|
@@ -111,6 +114,11 @@ func (r *Runer) InitConsumer() error { |
|
@@ -111,6 +114,11 @@ func (r *Runer) InitConsumer() error { |
111
|
}
|
114
|
}
|
112
|
|
115
|
|
113
|
func (r *Runer) Start(ctx context.Context) {
|
116
|
func (r *Runer) Start(ctx context.Context) {
|
|
|
117
|
+ defer func() {
|
|
|
118
|
+ if e := recover(); e != nil {
|
|
|
119
|
+ logs.Error(e)
|
|
|
120
|
+ }
|
|
|
121
|
+ }()
|
114
|
for {
|
122
|
for {
|
115
|
select {
|
123
|
select {
|
116
|
case <-ctx.Done():
|
124
|
case <-ctx.Done():
|