Thanks for your pointers. Much clearer now.
I have a first working version. There are still some rough edges (error checking ..), but I would like to have your opinion in the general structure
Requirements are simple:
1. Get some request from external provider
2. Extract some parameters and map them to some values
3. Encode a Json document
4. Push it to our kestrel cluster (memcached protocol)
5. Return the string "OK" (text/plain) to provider.
worker_processes 4;
error_log logs/error.log;
events {
worker_connections 1024;
}
http {
map $nativeStatus $TR18mappedStatus {
default NACK_FATAL;
# more values here ...
}
map $nativeError $TR18mappedError {
default 'Internal non mapped error';
# more values here ...
}
upstream dsrcluster {
server 192.168.1.226:22133;
server 192.168.1.227:22133;
keepalive 10;
}
server {
listen 8080;
location /tr18 {
default_type text/plain;
set $nativeStatus $arg_smsid;
set $nativeError $arg_smsid;
set $memc_value '{ "tr" : 18, "id" : "${arg_smsid}", "state": "${TR18mappedStatus}", "nativeStatus": "${nativeStatus}", "nativeErrorMessage" : "${nativeError}" }';
content_by_lua '
local res = ngx.location.capture("/kestrel", {args = { val = ngx.var.memc_value }})
ngx.say("OK")
';
}
location = /kestrel {
set $memc_key 'sirocco_dsr';
set $memc_cmd 'set';
set_unescape_uri $memc_value $arg_val;
memc_pass dsrcluster;
}
}
}
I have some doubts about using memc inside a lua location.capture() call, but I felt it was cleaner to select the back-end nginx way (btw, do not need any consistent backend selection; round robin works well in my case)
Thanks again.
Luis
El martes, 22 de enero de 2013 20:50:17 UTC+1, agentzh escribió:
Hello!
On Tue, Jan 22, 2013 at 11:44 AM, wrote:
> That´s what I was thinking, but I am completely new to both nginx and lua
> and my head was spinning.
>
I know, I know :) The following slides for my nginx/lua talks can be helpful:
http://openresty.org/#Presentations
and these articles and ebooks too:
http://openresty.org/#Resources
http://openresty.org/#eBooks
When in doubt, please don't hesitate to ask here :)
> btw, thanks for such a great nginx bundle. Our core software (SMS gateway)
> is going to be a lot simpler with openresty in front of it. We are updating
> it to handle all the incoming calls from sms aggregators and publishing an
> unified json model into our core system.
>
Great! I'm feeling honoured :)
Thanks!
-agentzh