how to watch etcd change with openresty

74 views
Skip to first unread message

forrest gan

unread,
Jun 14, 2017, 3:58:20 AM6/14/17
to openresty-en
I want to watch etcd value change, so I wrote some codes to test coroutine
http {
    include       mime.types;
lua_shared_dict routeIndicator 1m;
      default_type  application/octet-stream;
init_by_lua '
local routeIndicator = ngx.shared.routeIndicator;         
co=coroutine.create(function ()
  local index=0
  while(true)
  do
    local routeIndicator = ngx.shared.routeIndicator;
index=index+1  
routeIndicator:set("index", index)
                        ngx.sleep(5)
  end
         end)
coroutine.resume(co)
';

I found nothing happened? any idea

FQ Liu

unread,
Jun 14, 2017, 7:05:56 AM6/14/17
to openresty-en
ngx.sleep can not use in int_by_lua*

在 2017年6月14日星期三 UTC+8下午3:58:20,forrest gan写道:

Bingwu Yang

unread,
Jun 16, 2017, 3:07:03 AM6/16/17
to openre...@googlegroups.com
Hello.

Any HTTP client can talk to etcdv2 by HTTP. And you can talk to etcd
v2 with HTTP upon cosocket on OpenResty. A trick is you can create a
timer and send a HTTP request then wait something happened like read
timeout、closed、etcd response. when you got the events, you can decide
to how to deal with. if it's read timeout, you can restart the timer
or it's closed you can rewatch another etcdv2 instance, it's etcd
response you can restart the timer with the new index.

PS: you should carefully set the read timeout and the watch index.
> --
> You received this message because you are subscribed to the Google Groups
> "openresty-en" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to openresty-en...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

forrest gan

unread,
Jun 19, 2017, 6:20:36 AM6/19/17
to openresty-en
So tricky, so many tcp time out. Thanks.
Reply all
Reply to author
Forward
0 new messages