doujiang24 / lua-resty-kafka

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

batch mode for sync mode #95

Closed bdfy closed 4 years ago

bdfy commented 4 years ago

Hi I send, 1000 messages to kafka, using sync mode ( I don;t use async, because I have to get the status that all messages have reached):

`

for k,message in pairs(messages)  do

local ok, err = bp:send("test", key, message)

end

it works, but wait a long time for the result

But if i use buffer and batch_send:

`

local sendbuffer = self.sendbuffer

for k, message in pairs(messages) do

    sendbuffer:add(topic, partition_id, nil, message)

end

local ok = _batch_send(self, sendbuffer)

` it works much faster and it seems to work correctly.

If this works correctly, why not make this method public?

doujiang24 commented 4 years ago

@bdfy you can still get the status in async mode, by the error_handle: https://github.com/doujiang24/lua-resty-kafka#methods-1