File tree 3 files changed +19
-1
lines changed
3 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,20 @@ The ``user_db.txt`` is a text file with one entry per line::
60
60
user_id:username:user_token
61
61
62
62
63
+ Generating messages programmatically
64
+ ####################################
65
+
66
+ To pass a message to a WebSocket client through RabbitMQ you can use `pika ` Python module::
67
+
68
+ connection = pika.BlockingConnection()
69
+ channel = connection.channel()
70
+ channel.basic_publish(exchange='pushpull.ws',
71
+ # routing_key='pushpull.ws', # broadcast to all open WebSockets
72
+ routing_key=('pushpull.ws.%d' % user_id),
73
+ body='{"test": "Test"}')
74
+ connection.close()
75
+
76
+
63
77
64
78
Build docker image
65
79
##################
Original file line number Diff line number Diff line change 5
5
WEBSOCKET_URL = os .environ .get ('PUSHPULL_WEBSOCKET_URL' , '' )
6
6
BROKER_URL = os .environ .get ('PUSHPULL_BROKER_URL' , '' )
7
7
CORS_ALLOWED_ORIGINS = os .environ .get ('PUSHPULL_CORS_ALLOWED_ORIGINS' , '' )
8
+ AUTH_COOKIE = os .environ .get ('PUSHPULL_AUTH_COOKIE' , '' )
8
9
9
10
10
11
def get_host_port ():
Original file line number Diff line number Diff line change 17
17
18
18
19
19
async def websocket_rabbitmq_gateway (request ):
20
- authorization = decode_auth_querystring_param (request .GET )
20
+ if config .AUTH_COOKIE != '' :
21
+ authorization = request .cookies .get (config .AUTH_COOKIE );
22
+ else :
23
+ authorization = decode_auth_querystring_param (request .GET )
21
24
try :
22
25
# TODO: reuse amqp channel and maybe share it with the Exchanger
23
26
user_info = await auth .get_user_info (authorization )
You can’t perform that action at this time.
0 commit comments