doujiang24 / lua-resty-kafka

Lua kafka client driver for the Openresty based on the cosocket API
BSD 3-Clause "New" or "Revised" License
801 stars 274 forks source link

发送数据到kafka最终只落地到一个分区,查了下是因为每次有新的请求过来,correlation_id再次被初始化,这个问题有遇到吗? #100

Closed TomZou closed 3 years ago

TomZou commented 3 years ago

我使用共享内存解决了这个问题。 nginx.conf http模块增加lua_shared_dict shared_obj 10m; 初始化阶段 local shared_obj = ngx.shared.shared_obj shared_obj:set("correlation_id", 1)

在producer.lua里面获取和更新correlation_id

doujiang24 commented 3 years ago

不需要的,感觉是你用错了,obj = resty.kafka:new(...),obj 对象是可以跨请求复用的?

感觉你是没请求都 new 了一份?

TomZou commented 3 years ago

你好,我确实是每个请求都new了一个producer,所以导致了correlation_id每次都是一样的,请教一下你说的对象复用是在nginx哪个阶段做的吗?是再init_by_lua阶段还是在content_by_lua阶段呢?谢谢

------------------ 原始邮件 ------------------ 发件人: "doujiang24/lua-resty-kafka" <notifications@github.com>; 发送时间: 2020年8月19日(星期三) 中午11:42 收件人: "doujiang24/lua-resty-kafka"<lua-resty-kafka@noreply.github.com>; 抄送: ".追"<390788436@qq.com>;"Author"<author@noreply.github.com>; 主题: Re: [doujiang24/lua-resty-kafka] 发送数据到kafka最终只落地到一个分区,查了下是因为每次有新的请求过来,correlation_id再次被初始化,这个问题有遇到吗? (#100)

不需要的,感觉是你用错了,obj = resty.kafka:new(...),obj 对象是可以跨请求复用的?

感觉你是没请求都 new 了一份?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

doujiang24 commented 3 years ago

推荐是在 init_by_lua 里面完成