-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add otkafka processor #134
Conversation
Codecov Report
@@ Coverage Diff @@
## master #134 +/- ##
==========================================
+ Coverage 77.12% 77.40% +0.27%
==========================================
Files 84 86 +2
Lines 3205 3354 +149
==========================================
+ Hits 2472 2596 +124
- Misses 546 560 +14
- Partials 187 198 +11
Continue to review full report at Codecov.
|
otkafka/processor/processor.go
Outdated
return err | ||
} | ||
if h.batchFunc != nil { | ||
if h.info.autoCommit() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个区分真的有必要吗
otkafka/processor/processor.go
Outdated
return err | ||
} | ||
|
||
data = data[0:0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这块的含义是什么?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
推荐,doFunc从参数中接收 data和msg,而不是直接闭包使用。避免了很多可能出现的问题。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
处理成功之后, 清空切片. 闭包已经改了.
|
||
doFunc := func() error { | ||
if err := h.batchFunc(h.ctx, data); err != nil { | ||
return err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
发生错误时data和message没有清空,是故意的吗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
抛出去error了, 服务应该会退出, 就没管了
otkafka/processor/processor.go
Outdated
messages = append(messages, *v.message) | ||
if len(data) >= h.info.batchSize() { | ||
if err := doFunc(); err != nil { | ||
return err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个错误的测试用例很有必要。目前从代码分析应该是有问题的。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嗯, 补充了
// Note: | ||
// If sequence is necessary, make sure that per worker count is one. | ||
// Multiple goroutines cannot guarantee the order in which data is processed. | ||
type Info struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个用私有成员变量,公开方法更好吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的
What is it?
It is an abstraction of Kafka consumer process.
Users only need to care about how to parse message and process data (implements
processor.Handler
).They don't need to care about how to consume message and transfer data.
How to use it?