@@ -29,19 +29,24 @@ def list_rooms_for_user(self, user):
29
29
30
30
return rooms
31
31
32
+ channel = Noneq
33
+ def get_websocket_channel ():
34
+ import pika
35
+ from pika import BlockingConnection
36
+ global channel
37
+ if channel and channel .is_open :
38
+ return channel
39
+ connection_credentials = pika .PlainCredentials (settings .HIGH_TEMPLAR ['rabbitmq' ]['username' ],
40
+ settings .HIGH_TEMPLAR ['rabbitmq' ]['password' ])
41
+ connection_parameters = pika .ConnectionParameters (settings .HIGH_TEMPLAR ['rabbitmq' ]['host' ],
42
+ credentials = connection_credentials )
43
+ connection = BlockingConnection (parameters = connection_parameters )
44
+ channel = connection .channel ()
45
+ return channel
32
46
33
47
def trigger (data , rooms ):
34
48
if 'rabbitmq' in getattr (settings , 'HIGH_TEMPLAR' , {}):
35
- import pika
36
- from pika import BlockingConnection
37
-
38
- connection_credentials = pika .PlainCredentials (settings .HIGH_TEMPLAR ['rabbitmq' ]['username' ],
39
- settings .HIGH_TEMPLAR ['rabbitmq' ]['password' ])
40
- connection_parameters = pika .ConnectionParameters (settings .HIGH_TEMPLAR ['rabbitmq' ]['host' ],
41
- credentials = connection_credentials )
42
- connection = BlockingConnection (parameters = connection_parameters )
43
- channel = connection .channel ()
44
-
49
+ channel = get_websocket_channel ()
45
50
channel .basic_publish ('hightemplar' , routing_key = '*' , body = jsondumps ({
46
51
'data' : data ,
47
52
'rooms' : rooms ,
0 commit comments