-
Notifications
You must be signed in to change notification settings - Fork 55
Open
Description
Hi there,
I tried to follow the example you have here, I have little issue in this part of code.
--
-- Created by IntelliJ IDEA.
-- User: ismael
-- Date: 19/05/17
-- Time: 17:17
-- To change this template use File | Settings | File Templates.
--
local producer = require "rabbitmq"
local cjson = require "cjson"
local opts = {
username = "admin",
password = "desarrollo",
vhost = "/"
}
local mq, err = producer:new(opts)
if not mq then
ngx.say(cjson.encode({
success = false,
code = 0,
data = {
message = "Attempt to connect with rabbit failed. "
}
}))
return
end
mq:set_timeout(10000)
local ok, err = mq:connect("127.0.0.1", 61613)
if not ok then
ngx.say(cjson.encode({
success = false,
code = 1,
data = {
message = err
}
}))
return
end
local msg = {
success = true,
code = 2,
data = {
message = "All is fine!"
}
}
local headers = {}
headers['destination'] = "/exchange/test/binding"
headers['receipt'] = "msg#1"
headers['app-id'] = "luaresty"
headers['persistent'] = "true"
headers['content-type'] = "application/json"
local ok, err = mq:send(cjson.encode(msg), headers)
if not ok then
ngx.say(cjson.encode({
success = false,
code = 3,
data = {
message = err
}
}))
return
end
ngx.log(ngx.INFO, "Published : " .. cjson.encode(msg) )
local headers = {}
headers["destination"] = "/amq/queue/lua-queue"
headers["persistent"] = "true"
headers["id"] = "123"
local ok, err = mq:subscribe(headers)
if not ok then
ngx.say(cjson.encode({
success = false,
code = 4,
data = {
message = err
}
}))
return
end
ngx.log(ngx.INFO, "Ok: " .. ok)
local data, err = mq:receive()
if not data then
ngx.say(cjson.encode({
success = false,
code = 5,
data = {
message = err
}
}))
return
end
ngx.log(ngx.INFO, "Consumed: " .. data)
local data, err = mq:receive()
if not data then
ngx.say(cjson.encode({
success = false,
code = 5,
data = {
message = err
}
}))
return
endI cand send messages to rabbit well, to prove that I have the following information in nginx logs.
[lua] queu.lua:75: Published : {"data":{"message":"All is fine!"},"code":2,"success":true}
In my browser I'm getting this. It appears the connection with rabbit has been close earlier, but I don't know why.
{"data":{"message":"closed"},"code":5,"success":false}
What am I doing wrong?
What am I missing?
Metadata
Metadata
Assignees
Labels
No labels