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

runtime error: content_by_lua(lua-kafka.conf:50):21: Cannot serialise table #26

Closed lovemelovemycode closed 8 years ago

lovemelovemycode commented 8 years ago

1 部署环境 openresty-1.9.15.1.tar.gz + 最新lua-resty-kafka + CDH5.4.0(kafka1.3.0)+ CentOS6.4 64位

2 lua-resty-kafka相应的nginx配置文件内容

server { listen 8081; server_name 192.168.15.84; location /test { content_by_lua ' local cjson = require "cjson" local client = require "resty.kafka.client" local producer = require "resty.kafka.producer"

            local broker_list = {
                { host = "192.168.15.81", port = 9092 },
                { host = "192.168.15.82", port = 9092 },
                { host = "192.168.15.83", port = 9092 }
            }

            local key = "key"
            local message = "halo world"

            -- usually we do not use this library directly
            local cli = client:new(broker_list)
            local brokers, partitions = cli:fetch_metadata("test")
            if not brokers then
                ngx.say("fetch_metadata failed, err:", partitions)
            end
            ngx.say("brokers: ", cjson.encode(brokers), "; partitions: ", cjson.encode(partitions))

            -- sync producer_type
            local p = producer:new(broker_list)

            local offset, err = p:send("test", key, message)
            if not offset then
                ngx.say("send err:", err)
                return
            end
            ngx.say("send success, offset: ", tonumber(offset))

            -- this is async producer_type and bp will be reused in the whole nginx worker
            local bp = producer:new(broker_list, { producer_type = "async" })

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

            ngx.say("send success, ok:", ok)
        ';
}

}

3 请求例子 curl -X POST -H ' charset=UTF-8' -d 'sssss' http://192.168.15.84:8081/test

4 出现的问题(数据不能写入kafka),日志详情如下: 2016/06/21 18:10:30 [error] 22381#0: *1 lua entry thread aborted: runtime error: content_by_lua(lua-kafka.conf:50):21: Cannot serialise table: excessively sparse array stack traceback: coroutine 0: [C]: in function 'encode' content_by_lua(lua-kafka.conf:50):21: in function <content_by_lua(lua-kafka.conf:50):1>, client: 192.168.15.84, server: 192.168.15.84, request: "POST /test HTTP/1.1", host: "192.168.15.84:8081"

5 非常感谢,期待您的回答。

lovemelovemycode commented 8 years ago

1 出现错误的代码行: producer.lua ---》local function _send(self, broker_conf, topic_partitions)---》resp, err, retryable = bk:send_receive(req)

2 err信息:no resolver defined to resolve "datanode03.jj.wl"

doujiang24 commented 8 years ago

@lovemelovemycode You can find answers from: https://github.com/doujiang24/lua-resty-kafka/issues/21 https://github.com/doujiang24/lua-resty-kafka/issues/5

doujiang24 commented 8 years ago

considered resolved