Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Receive sents me an error with message "Closed" #11

Open
JasterTDC opened this issue May 19, 2017 · 4 comments
Open

Receive sents me an error with message "Closed" #11

JasterTDC opened this issue May 19, 2017 · 4 comments

Comments

@JasterTDC
Copy link

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
end

I 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?

@jlcoding
Copy link

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
end

I 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?

i have a same problem

@shuxiao9058
Copy link

the same issue

@rohityadavcloud
Copy link
Contributor

cc @ankneo

@ankneo
Copy link
Member

ankneo commented Dec 3, 2021

PRs are welcome. The project is not actively used anymore internally, hence no more commits by Wingify.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants