如何要求枪支并与达芙妮做出回应?使用Django频道,Nginx,Gunicorn,Daphne

发布于 2025-01-22 11:11:42 字数 757 浏览 0 评论 0原文

我在与Nginx,Daphne和Gunicorn一起部署Django应用程序时面临一个奇怪的问题。

截至目前,我已经成功部署了我的Django应用程序。 我的HTTP请求由Gunicorn处理,WSS请求由达芙妮(Daphne)处理,这本来可以发生。

考虑一个方案,我将HTTP请求发送给Gunicorn,Django需要通过频道发送消息。我该怎么做?

例如,如果我通过http post请求添加了帖子,并且想通过渠道向所有开放渠道发送通知(我有一个列表),即使在要求HTTP首先是通过枪支收到的吗?

我需要的请求流是:

客户端> http> nginx> Gunicorn> django>进行一些处理>通过WSS&GT将通知发送到所有开放渠道;发送http响应ok状态= 200给客户端

我使用本指南来部署

https://github.com/mitchtabian/howto-django-channels-daphne/blob/blob/master/master/readme.md

一切正常,除了我没有在客户端网络网络上收到WSS消息,当我将HTTP请求发送给Gunicorn时,但是当我向Daphne发送HTTP请求时,我会成功获得WSS响应

I'm facing a strange issue in deploying Django app with Nginx, Daphne and Gunicorn.

As of now, I have successfully deployed my Django app.
My HTTP requests are handled by Gunicorn, and WSS requests are handled by Daphne, which is meant to happen.

Consider a scenario, where I send an HTTP request to Gunicorn, and Django needs to send a message back via channels. How do I do that?

For example, if I add a post via HTTP POST request, and want to send a notification via channels to all the open channels (which I have a list of) how do I make Django send back a channel message through Daphne, even when the request was HTTP in the first place received through Gunicorn?

The request flow that I need is:

Client > HTTP > NGINX > GUNICORN > DJANGO > Do some processing > Send notification to all open channels via WSS > Send HTTP RESPONSE OK STATUS=200 to client

I used this guide to deploy

https://github.com/mitchtabian/HOWTO-django-channels-daphne/blob/master/README.md

Everything is working fine except I don't receive WSS messages on the client WebSocket listener, when I send a HTTP request to Gunicorn, but when I send HTTP request to Daphne I get a WSS response successfully

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吻安 2025-01-29 11:11:42

您需要配置a Channel layer layer

频道层允许您在应用程序的不同实例之间进行交谈。

channels_redis 是一个很好的选择,是将消息从服​​务器传输到另一个。

请求流将是:

Client request -> NGINX -> Gunicorn -> Django Application -> Send notification  -> Redis -> Websocket Consumer -> Send response

You need to configure a Channel Layer:

Channel layers allow you to talk between different instances of an application.

channels_redis is a good one, to transfer a message from a server to another.

The request flow will be:

Client request -> NGINX -> Gunicorn -> Django Application -> Send notification  -> Redis -> Websocket Consumer -> Send response
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文