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

fix: handle unknown errcode #132

Merged
merged 4 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/resty/kafka/basic-consumer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ function _M.list_offset(self, topic, partition, timestamp)

local errcode = data.errcode
if errcode ~= 0 then
err = Errors[errcode].msg
err = Errors[errcode] or Errors[-1]

ngx_log(INFO, "list offset err: ", err, ", topic: ", topic,
ngx_log(INFO, "list offset err: ", err.msg, "(", errcode, "), topic: ", topic,
", partition_id: ", partition)

return nil, err
return nil, err.msg
end

return data.offset, nil
Expand Down Expand Up @@ -136,12 +136,12 @@ function _M.fetch(self, topic, partition, offset)

local errcode = data.errcode
if errcode ~= 0 then
err = Errors[errcode].msg
err = Errors[errcode] or Errors[-1]

ngx_log(INFO, "fetch message err: ", err, ", topic: ", topic,
ngx_log(INFO, "fetch message err: ", err.msg, "(", errcode, "), topic: ", topic,
", partition_id: ", partition)

return nil, err
return nil, err.msg
end

return data, nil
Expand Down
3 changes: 2 additions & 1 deletion lib/resty/kafka/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ local function _fetch_api_versions(broker, client_id)
local errcode, api_versions = api_versions_decode(resp)

if errcode ~= 0 then
return nil, Errors[err]
local err = Errors[errcode] or Errors[-1]
return nil, err.msg
else
return api_versions, nil
end
Expand Down
6 changes: 3 additions & 3 deletions lib/resty/kafka/producer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@ local function _send(self, broker_conf, topic_partitions)
sendbuffer:offset(topic, partition_id, r.offset)
sendbuffer:clear(topic, partition_id)
else
err = Errors[errcode]
err = Errors[errcode] or Errors[-1]

-- set retries according to the error list
local retryable0 = retryable or err.retriable

local index = sendbuffer:err(topic, partition_id, err.msg, retryable0)

ngx_log(INFO, "retry to send messages to kafka err: ", err.msg, ", retryable: ", retryable0,
", topic: ", topic, ", partition_id: ", partition_id, ", length: ", index / 2)
ngx_log(INFO, "retry to send messages to kafka err: ", err.msg, "(", errcode, "), retryable: ",
retryable0, ", topic: ", topic, ", partition_id: ", partition_id, ", length: ", index / 2)
end
end
end
Expand Down