Closed sstong123 closed 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).
in the async model,I want to say("send err:", err) on the page when the kafka is offline . how to do it?
no way, you have to use sync
model then.
seems sync model's performance is very low.
yeah, you have to balance it, you can not want them both :<
@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!
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.