Skip to content

Commit 08a79a8

Browse files
authored
Merge pull request #2 from ingresse/feature/exchange-subscribe
Adding method to subscribe to a exchange
2 parents 86c9299 + edb7726 commit 08a79a8

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

message_queue/adapters/amqp_adapter.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,26 @@ def _consume_acknowledge(self, channel, tag, acknowledge=True):
171171

172172
channel.basic_ack(delivery_tag=tag)
173173

174+
def subscribe(self, exchange, queue, exchange_type="fanout", **kwargs):
175+
"""Subscribes to a exchange.
176+
177+
:param function worker: Method that consume the message
178+
:param string exchange: Exchange name
179+
:param string exchange: Queue name
180+
:param string exchange_type: Exchange type
181+
182+
"""
183+
self.queue = queue
184+
self.channel.exchange_declare(
185+
exchange=exchange, exchange_type=exchange_type)
186+
187+
self.channel.queue_declare(
188+
queue=self.queue,
189+
passive=kwargs.get('passive', False),
190+
durable=kwargs.get('durable', True),
191+
exclusive=kwargs.get('exclusive', False),
192+
auto_delete=kwargs.get('auto_delete', False),
193+
arguments=kwargs.get('arguments', None)
194+
)
195+
196+
self.channel.queue_bind(exchange=exchange, queue=self.queue)

0 commit comments

Comments
 (0)