-
-
Notifications
You must be signed in to change notification settings - Fork 627
Closed
Description
Hi!
- I have an issue and I cannot resolve it, please help me
- Overview: I have 2 services. 1 is call_service and 2 is socker_service and they connect together via the message queue of Redis
- Here is my code:
-
apps.socket.views.py:
sio = socketio.Server(async_mode='eventlet', cors_allowed_origins='*', logger=True, engineio_logger=True) -
wsgi.py:
import os
from threading import Thread
import eventlet.wsgi
import socketio
from common_modules.core.redis import RedisConnection
from common_modules.utils.channel import WAIT_ACTION
from django.core.wsgi import get_wsgi_application
from apps.socket.views import sio
from services.socket import SocketService
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'socket_service.settings')
application = get_wsgi_application()
application = socketio.WSGIApp(sio, application)
def start_subscribe_message():
def run():
socket_service = SocketService()
redis_queue = RedisConnection().established_connection()
pubsub = redis_queue.pubsub()
queues = [WAIT_ACTION]
for queue in queues:
pubsub.subscribe(queue)
for message in pubsub.listen():
if message:
channel = message.get('channel', '')
if channel.decode("utf-8") == WAIT_ACTION:
data = message.get('data', '')
print(data)
if data != 1:
data = data.decode('utf-8').replace("'", '"')
print("sio wait: " + str(id(sio)))
sio.emit(event='wait-action', data="PONG wait")
thread = Thread(target=run)
thread.start()
start_subscribe_message()
eventlet.wsgi.server(eventlet.listen(('', 8400)), application)
- Issue:
When I publish a message to Redis with channel WAIT_ACTION, the Redis queue still receives this message. But when I want to emit data to the Client with channel wait-action, the program run to the line sio.emit(event='wait-action', data="PONG wait"). It logs for me like that:
emitting event "wait-action" to all [/]
BY6k3x2lVvrZ3kAqAAAA: Sending packet MESSAGE data 2["wait-action","PONG wait"]
BY6k3x2lVvrZ3kAqAAAA: Sending packet PING data None
BY6k3x2lVvrZ3kAqAAAA: Unexpected error "timed out", closing connection
127.0.0.1 - - [14/Sep/2022 00:33:47] "GET /socket.io/?EIO=4&transport=websocket HTTP/1.1" 200 0 45.014668 - requirements.txt:
asgiref==3.5.2
async-timeout==4.0.2
backports.zoneinfo==0.2.1
bidict==0.22.0
common==0.1.1
Deprecated==1.2.13
Django==4.1.1
djangorestframework==3.13.1
dnspython==2.2.1
eventlet==0.33.1
greenlet==1.1.3
mysqlclient==2.1.1
packaging==21.3
pyparsing==3.0.9
python-engineio==4.3.4
python-socketio==5.7.1
pytz==2022.2.1
redis==4.3.4
six==1.16.0
sqlparse==0.4.2
wrapt==1.14.1
Metadata
Metadata
Assignees
Labels
No labels