Skip to content
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

和Kratos适配时,优雅关闭问题。 #37

Closed
chazex opened this issue Dec 13, 2022 · 3 comments
Closed

和Kratos适配时,优雅关闭问题。 #37

chazex opened this issue Dec 13, 2022 · 3 comments

Comments

@chazex
Copy link

chazex commented Dec 13, 2022

Hi,
我现在使用Kratos框架,server使用的是 kratos-transport的kafka。
有如下疑问:

  1. 优雅关闭消费者时,kratos-transport是通过 context机制来实现的(server.Stop()函数不生效)。subscribe的context是通过kafkaSrv.RegisterSubscriber()来设置的,在与Kratos结合时,subscribe的context应该与Kratos.App.ctx关联起来,在Kratos的layout中,Server是单独一个目录 internal/server/xxx.go,关联起来不是很方便,有什么好的方法吗?
  2. subscribe 使用 context来关闭,会出现一个问题。如果一个消息正在消费(处理业务逻辑),此时收到了优雅关闭信号,context被取消,此时可能收到错误 ERROR msg=[kafka]: unable to commit msg: context canceled, 待服务重启后,会出现二次消费的问题。
@farums
Copy link

farums commented Jun 5, 2023

kratos-transport up в
type headerCarrier struct{} add
Keys() []string
Values(key string) []string

@tx7do
Copy link
Owner

tx7do commented Jun 10, 2023

kratos-transport up в
type headerCarrier struct{} add
Keys() []string
Values(key string) []string

already fixed

@xichengliudui
Copy link

@chazex 请问如何通过 context 来设置优雅退出?
当我发现 server.Stop() 不生效时,我修改了取消订阅 s.reader.Close(), 但是同样会有二次消费的问题。

@tx7do tx7do closed this as completed May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants