Skip to content

Commit 73fd499

Browse files
correct kombu implementation of a fanout queue
1 parent 12dfcf8 commit 73fd499

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

socketio/kombu_manager.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pickle
2+
import uuid
23

34
try:
45
import kombu
@@ -40,15 +41,17 @@ def __init__(self, url='amqp://guest:guest@localhost:5672//',
4041
'(Run "pip install kombu" in your '
4142
'virtualenv).')
4243
self.kombu = kombu.Connection(url)
43-
self.queue = self.kombu.SimpleQueue(channel)
44+
self.exchange = kombu.Exchange(channel, type='fanout', durable=False)
45+
self.queue = kombu.Queue(str(uuid.uuid4()), self.exchange)
4446
super(KombuManager, self).__init__(channel=channel)
4547

4648
def _publish(self, data):
47-
return self.queue.put(pickle.dumps(data))
49+
with self.kombu.SimpleQueue(self.queue) as queue:
50+
queue.put(pickle.dumps(data))
4851

4952
def _listen(self):
50-
listen_queue = self.kombu.SimpleQueue(self.channel)
51-
while True:
52-
message = listen_queue.get(block=True)
53-
message.ack()
54-
yield message.payload
53+
with self.kombu.SimpleQueue(self.queue) as queue:
54+
while True:
55+
message = queue.get(block=True)
56+
message.ack()
57+
yield message.payload

0 commit comments

Comments
 (0)