请教一个问题,为使用lus-resty-rabbitmqstomp库,进行消费rabbitmq的数据的时候,可以正常连通但是每次消费的时候都会漏掉数据,比如说为队列中有10条数据,我receive一次会给我返回一条数据,然后队列里面其他的数据就都没有了,请问是headers里面需要添加什么参数吗?我的代码如下:
local cjson = require "cjson"
local rabbitmq = require "resty.rabbitmqstomp"
local opts = {username = "root",
password = "root123",
vhost = "/" }
local mq, err = rabbitmq:new(opts)
if not mq then
ngx.log(ngx.ERR,"rabbitmq new failed: ",err)
return
end
mq:set_timeout(1000)
local ok, err = mq:connect("127.0.0.1",61613)
if not ok then
ngx.log(ngx.ERR,"connect rabbitmq failed: ",err)
mq:close()
return
end
local headers = {}
--headers["destination"] = "/amq/queue/q.cguardian.categoryStatusChange"
headers["destination"] = "/queue/q.cguardian.categoryStatusChange"
headers["persistent"] = "true"
headers["id"] = "123"
headers["ack"] = "auto"
headers["prefetch-count"] = "1"
local ok, err = mq:subscribe(headers)
if not ok then
ngx.log(ngx.ERR,"subscribe failed: ",err)
mq:close()
return
end
local data, err = mq:receive()
if not ok then
ngx.log(ngx.ERR,"receive failed: ",err)
mq:close()
return
end
if data == nil then
ngx.log(ngx.ERR,"data is null")
mq:close()
return
end
ngx.say(type(data))
ngx.say(cjson.encode(data))
ngx.log(ngx.INFO, "Consumed: "..data)
local headers = {}
headers["persistent"] = "true"
headers["id"] = "123"
local ok ,err = mq:unsubscribe(headers)
local ok,err = mq:set_keepalive(10000,10000)
if not ok then
ngx.log(ngx.ERR,"set keepalive failed: ",err)
return
end