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

当在producer中设置required_acks为0的时候,会出现timeout异常【when set required_acks=0 in producer, it will throw 'producer.lua:272: buffered messages send to kafka err: timeout'】 #105

Closed kxbin closed 3 years ago

kxbin commented 3 years ago

你好,当在resty.kafka.producer中设置required_acks为0的时候,会出现timeout异常,但实际上message已被kafka接收。

原因是lua-resty-kafka在发送消息后,无论required_acks如何设置,都会等待kafka服务端回复确认,但实际上如果acks为0,kafka服务端将不会回复确认,所以出现timeout异常。

【Hello, when set required_acks=0 in producer, it will throw 'producer.lua:272: buffered messages send to kafka err: timeout' exception, but kafka server can receive message in fact. Because after lua-resty-kafka send message, No matter how the required_acks set, lua-resty-kafka will wait kafka server response anytime, but if set acks=0, the kafka server will don't response in fact.】

异常信息:【exception info】

producer.lua:272: buffered messages send to kafka err: timeout

broker.lua相关代码,这里需要判断required_acks参数:【broker.lua bug code, need check required_acks in there】

function _M.send_receive(self, request)
    local sock, err = tcp()
    if not sock then
        return nil, err, true
    end

    sock:settimeout(self.config.socket_timeout)

    local ok, err = sock:connect(self.host, self.port)
    if not ok then
        return nil, err, true
    end

    local bytes, err = sock:send(request:package())
    if not bytes then
        return nil, err, true
    end

    local data, err = sock:receive(4)
kxbin commented 3 years ago

hello

hongliang5316 commented 3 years ago

@kxbin hello, 这里https://github.com/doujiang24/lua-resty-kafka#methods-1, required_acks还不支持为0

kxbin commented 3 years ago

@kxbin hello, 这里https://github.com/doujiang24/lua-resty-kafka#methods-1, required_acks还不支持为0

才看到,谢谢