Написал групповой чат с применением (Django 1.10 Channels 1.8 Daphne 1.4 Redis-server)
и как ни странно получилось задеплоить с первого раза чат заработал тестировали 10-11 человек все было норм решили открыть для всех вот тут все и началось чат лёг и после этого уже перестал запускаться
WebSocket connection to 'wss://example.com/dashboard/chat/' failed: WebSocket is closed before the connection is established
CHANNEL_LAYERS = { "default": { # This example app uses the Redis channel layer implementation asgi_redis "BACKEND": "asgi_redis.RedisChannelLayer", 'CONFIG': { "hosts": [os.environ.get('REDIS_URL', 'redis://localhost:6379')], } "ROUTING": "stp.routing.channel_routing", # We will create it in a moment }, }
from channels import include channel_routing = [ include('multichat.routing.chat_routing', path=r"^/dashboard/chat/"), ]
from channels.routing import route from multichat.consumers import * chat_routing = [ route("websocket.connect", chat_connect), route("websocket.receive", chat_receive), route("websocket.disconnect", chat_disconnect) ]
@channel_session_user_from_http def chat_connect(message): logger.info('websocket_connect. message = %s', message) Group("all").add(message.reply_channel) Room.objects.add("all", message.reply_channel.name, message.user) message.reply_channel.send({"accept": True})
location /dashboard/chat/ { proxy_pass http://0.0.0.0:8001; proxy_http_version 1.1; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; }
./manage.py runworker --traceback 2018-03-06 18:28:10,456 - INFO - runworker - Using single-threaded worker. 2018-03-06 18:28:10,456 - INFO - runworker - Running worker against channel layer default (asgi_redis.core.RedisChannelLayer) 2018-03-06 18:28:10,457 - INFO - worker - Listening on channels http.request, websocket.connect, websocket.disconnect, websocket.receive
daphne -b 0.0.0.0 -p 8001 stp.asgi:channel_layer 2018-03-06 18:29:57,498 INFO Starting server at tcp:port=8001:interface=0.0.0.0, channel layer stp.asgi:channel_layer. 2018-03-06 18:29:57,499 INFO HTTP/2 support not enabled (install the http2 and tls Twisted extras) 2018-03-06 18:29:57,499 INFO Using busy-loop synchronous mode on channel layer 2018-03-06 18:29:57,499 INFO Listening on endpoint tcp:port=8001:interface=0.0.0.0 127.0.0.1:55384 - - [06/Mar/2018:18:30:23] "WSCONNECTING /dashboard/chat/" - - 127.0.0.1:55384 - - [06/Mar/2018:18:30:25] "WSDISCONNECT /dashboard/chat/" - - 127.0.0.1:55478 - - [06/Mar/2018:18:30:55] "WSCONNECTING /dashboard/chat/" - - 127.0.0.1:55478 - - [06/Mar/2018:18:30:57] "WSDISCONNECT /dashboard/chat/" - - 127.0.0.1:56066 - - [06/Mar/2018:18:31:27] "WSCONNECTING /dashboard/chat/" - - 127.0.0.1:56066 - - [06/Mar/2018:18:31:29] "WSDISCONNECT /dashboard/chat/" - -
но походу где-то бяда между daphne и backend chanels потому-что до consumers.py и не доходит логер нечего не выводит Вообщем засада буду признателен за любую помощь!
С уважением Сергей.