وصفات Nginx: إعلامات غير متزامنة من PostgreSQL إلى websocket

لإعداد إشعارات غير متزامنة من PostgreSQL إلى websocket ، نحتاج إلى nginx نفسه والإضافات الخاصة به postgres ، و push-stream ، و set-misc . (لقد قدمت روابط إلى شوكة بلدي ، لأنني أجريت بعض التغييرات التي تعذر دفعها إلى المستودعات الأصلية حتى الآن. يمكنك أيضًا استخدام الصورة الجاهزة .)

لتوصيل العملاء بـ nginx عبر websocket ، قم بإنشاء

location =/websocket { push_stream_subscriber websocket; #    websocket push_stream_channels_path $arg_id; #   websocket    id push_stream_websocket_allow_publish on; #   -    push_stream_client_subscribed_request /subscribe; #        push_stream_client_unsubscribed_request /unsubscribe; #        push_stream_client_publish_request /publish; #         websocket } 

عند توصيل عميل بـ websocket ، نبدأ في الاستماع إلى الإشعارات غير المتزامنة في PostgreSQL

 location =/subscribe { internal; postgres_pass ngx; #    PostgreSQL set_quote_json_str $channel $arg_id; #    postgres_query "listen $channel"; #     } 

عند فصل عميل عن websocket ، نتوقف عن الاستماع إلى الإشعارات غير المتزامنة في PostgreSQL

 location =/unsubscribe { internal; postgres_pass ngx; #    PostgreSQL set_quote_json_str $channel $arg_id; #    postgres_query "unlisten $channel"; #     } 

عندما ينشر أحد العملاء إلى websocket ، فإننا نفعل شيئًا ما

 location =/publish { internal; postgres_pass ngx; #    PostgreSQL postgres_query "select now()"; #    PostgreSQL      websocket } 

أيضا ، يمكنك فقط إرسال شيء إلى العميل في websocket

 location =/publisher { allow 127.0.0.1/16; #     deny all; #     push_stream_channel_info_on_publish off; #         push_stream_publisher; #   push_stream_channels_path $arg_id; #   websocket    id } 

Source: https://habr.com/ru/post/ar456672/


All Articles