Skip to content

Commit 03245bb

Browse files
author
Stefan Majoor
committed
xxx
1 parent 9e8bd20 commit 03245bb

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

binder/websocket.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,23 @@ def list_rooms_for_user(self, user):
2929

3030
return rooms
3131

32+
def get_websocket_channel():
33+
import pika
34+
from pika import BlockingConnection
35+
global channel
36+
if channel and channel.is_open:
37+
return channel
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+
return channel
3245

3346
def trigger(data, rooms):
3447
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-
48+
channel = get_channel()
4549
channel.basic_publish('hightemplar', routing_key='*', body=jsondumps({
4650
'data': data,
4751
'rooms': rooms,

0 commit comments

Comments
 (0)