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

Getting 'no request' error with producer. #54

Closed hartfordfive closed 7 years ago

hartfordfive commented 7 years ago

I've attempted to use the Kafka producer to send messages to a Kafka instance on the same local private network. Here's an example of the relevant kafka producer code that I'm using:

_kafka_broker_list = {
  {host = "10.10.250.10", port = 9092}
}
_kafka_producer = _kafka:new(_kafka_broker_list, {producer_type = "async"})

-- Other work gets done here

local kafka_send_ok, kafka_send_err = _kafka_producer:send(list, "nginx", '{"message": "this is a test", "type": "test"}')
if not kafka_send_ok then
   ngx.log(ngx.ERR, "Could not send message to Kafka broker:", kafka_send_err)
   return
end

but unfortunately I get this error when I start nginx:

2017/05/09 18:07:17 [error] 8#8: init_by_lua error: /usr/local/openresty/site/lualib/resty/kafka/producer.lua:282: no request
stack traceback:
    [C]: in function 'timer_at'
    /usr/local/openresty/site/lualib/resty/kafka/producer.lua:282: in function '_flush_buffer'
    /usr/local/openresty/site/lualib/resty/kafka/producer.lua:291: in function '_timer_flush'
    /usr/local/openresty/site/lualib/resty/kafka/producer.lua:333: in function 'new'
    init_by_lua:51: in main chunk

I can't seem to figure out why I'm getting this. Would you have any ideas? Thanks for your help.

doujiang24 commented 7 years ago

Seems you are calling send in init_by_lua, that's not allowed. https://github.com/openresty/lua-nginx-module/#ngxtimerat