Writing AMQP/Lua cosocket api based lib Vs. writing nginx C module

65 views
Skip to first unread message

Rohit Yadav

unread,
May 17, 2013, 11:56:05 AM5/17/13
to openre...@googlegroups.com, open...@googlegroups.com
Hi,

I'm trying to implement a fast openresty/lua based request handler which could write processed data directly to RabbitMQ. I could not find any production grade amqp/lua library which is non-blocking and reuses a connection pool or is based on cosocket API.

But I could find a good C based amqp library, so one way could be to write a C based nginx module. (can one get access to lua_shared_dicts from a C based nginx/module?)

Another way is to write my own lua library based on cosocket api and opensource it. I don't know anything about writing nginx module or lua/cosocket api based library but I've anticipated these two options and I'm going with either of these two options.

Pl. advise? Which would be the best approach for my use case.

Regards,
Rohit Yadav

Simon

unread,
May 17, 2013, 8:32:37 PM5/17/13
to open...@googlegroups.com
Writing Nginx module is more difficult than lua-resty module. If the amqp protocol is not complicated, it is better to write a lua-resty lib.

And I think the c amqp lib could not be used directly in nginx moudle, because of nginx event mechenism. You might to modify network part of the amqp client, and use nginx upstream. But in lua, you need not to care about that.

Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

agentzh

unread,
May 22, 2013, 1:59:20 PM5/22/13
to openresty, openresty-en
Hello!

On Wed, May 22, 2013 at 1:13 AM, <llb...@gmail.com> wrote:
>
> Lua has rabbitmq client library https://github.com/tcoram/rabbitmq-lua.
>
> Can it use directly ?
>

No, it will surely block the Nginx worker processes and ruin the
performance. To quote the related parts in ngx_lua's official
documentation:

"Network I/O operations in user code should only be done through the
Nginx Lua API calls as the Nginx event loop may be blocked and
performance drop off dramatically otherwise."

See http://wiki.nginx.org/HttpLuaModule#Nginx_API_for_Lua

To summarize, you should only use a client library

1. based on either ngx_lua's cosocket API or
2. implemented as an Nginx upstream C module (and accessed by Nginx
subrequests).

Best regards,
-agentzh
Reply all
Reply to author
Forward
0 new messages