Home:ALL Converter>How to request to Gunicorn and respond with Daphne? Using Django channels, Nginx, Gunicorn, Daphne

How to request to Gunicorn and respond with Daphne? Using Django channels, Nginx, Gunicorn, Daphne

Ask Time:2022-04-19T17:45:53         Author:Tushar Kulkarni

Json Formatter

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

Author:Tushar Kulkarni,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/71922881/how-to-request-to-gunicorn-and-respond-with-daphne-using-django-channels-nginx
yy