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

use websocket client to sync data in local redis before nginx is accessible #63

Open
x-077 opened this issue Jul 19, 2021 · 5 comments
Open

Comments

@x-077
Copy link

x-077 commented Jul 19, 2021

Hello,

Im not sure if that's possible but before I look at openresty / LUA scripting, within my microservice (nodejs), I had a websocket client that was connecting to a remote server to sync up data into redis before the service was accessible.

Those data are relative to the authentication of the users, routes, certificates and should be available before the service is up.

Can I do the same thing directly on nginx level using LUA ( and lua-resty-weboscket / lua-resty-redis ) ? As websocket and redis are not usuable in the init_* block, Im wondering how I could proceed.

Thanks

@zhuizhuhaomeng
Copy link
Contributor

sync data in the priviledge process, drop the request before the sync is completed.

@x-077
Copy link
Author

x-077 commented Jul 23, 2021

Hello @zhuizhuhaomeng ,

Im not sure to understand. openresty is quite new for me could you please be a bit more specific ?

Thanks

@doujiang24
Copy link
Member

@matth-c3

Can I do the same thing directly on nginx level using LUA
Could you please clarify the "same thing"? Do you want to use openresty to build a WebSocket server?

@x-077
Copy link
Author

x-077 commented Jul 26, 2021

Hello @doujiang24 ,

No, I would like to use the lua-resty-websocket client to establish a persistant connection to a remote server, before openresty/nginx is resdy to accept connections. I would do that in the init_* block but its not possible with lua-resty-{weboscket / redis }.

@doujiang24
Copy link
Member

okay, you can create a zero delay timer in init_worker_by_lua, like

init_worker_by_lua_block {
  local ok, err = ngx.timer.at(0, websocket_client_func)
}

you can do anything in the websocket_client_func then.

but just be noticed that the timer runs asynchronous, it won't stop openresty to accept connections.

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

3 participants