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

local ok, err = bp:send(topicName, key, message) ,ok always return true even the kakfa server closed. #65

Closed sstong123 closed 6 years ago

sstong123 commented 6 years ago

local bp = producer:new(broker_list, { producer_type = "async" })

local ok, err = bp:send(topicName, key, message) if not ok then ngx.say("send err:", err) return end

I never see ngx.say("send err:", err) run after the kafak server closed,and find the ok is always true.

doujiang24 commented 6 years ago
In async model
The message will write to the buffer first. It will send to the kafka server when the buffer exceed the batch_num, or every flush_time flush the buffer.
It case of success, returns true. In case of errors, returns nil with a string describing the error (buffer overflow).

https://github.com/doujiang24/lua-resty-kafka#send

sstong123 commented 6 years ago

in the async model,I want to say("send err:", err) on the page when the kafka is offline . how to do it?

doujiang24 commented 6 years ago

no way, you have to use sync model then.

sstong123 commented 6 years ago

seems sync model's performance is very low.

doujiang24 commented 6 years ago

yeah, you have to balance it, you can not want them both :<

rhapsodyv commented 1 year ago

@doujiang24 Sorry for bring an old topic up, but I didn't find a better place to ask.

For my current use case, I can't use the async producer, as I need give some guarantee to the client that the data was saved. If there's any error, they have backoff and monitoring to help.

So, I need to use the sync option. But, I saw that the sync version could be a little slow, main because of the object creation and connect.

The question is: can I have only one producer instance per worker (using init_by_lua_block), shared among all requests? Do it handle concurrent send calls?

Or maybe, is there any way to use the async producer, but actual wait for the response of the current send?

Something like having the a data object instance that keeps the state of this current send call, so all the producer code doesn't have any internal state and just use the supplied data object?

Thanks for you response! And congrats for this great work!