为了准备从PostgreSQL到websocket的异步通知,我们需要
nginx本身及其插件
postgres ,
push-stream和
set-misc 。 (我提供了到fork的链接,因为我做了一些尚未塞入原始存储库的更改。您还可以使用
现成的图像 。)
要将客户端通过websocket连接到nginx,请创建
location =/websocket { push_stream_subscriber websocket;
将客户端连接到Websocket时,我们开始监听PostgreSQL中的异步通知
location =/subscribe { internal; postgres_pass ngx;
当客户端与WebSocket断开连接时,我们将停止监听PostgreSQL中的异步通知
location =/unsubscribe { internal; postgres_pass ngx;
当客户发布到websocket时,我们会做一些事情
location =/publish { internal; postgres_pass ngx;
另外,您可以只在websocket中向客户端发送一些内容
location =/publisher { allow 127.0.0.1/16;