This document is for Kombu's development version, which can be significantly different from previous releases. Get the stable docs here: 5.0.
Kombu - kombu
¶
Messaging library for Python.
Connection¶
Exchange¶
Example creating an exchange declaration:
>>> news_exchange = Exchange('news', type='topic')
For now news_exchange is just a declaration, you can’t perform actions on it. It just describes the name and options for the exchange.
The exchange can be bound or unbound. Bound means the exchange is associated with a channel and operations can be performed on it. To bind the exchange you call the exchange with the channel as argument:
>>> bound_exchange = news_exchange(channel)
Now you can perform operations like declare()
or delete()
:
>>> # Declare exchange manually
>>> bound_exchange.declare()
>>> # Publish raw string message using low-level exchange API
>>> bound_exchange.publish(
... 'Cure for cancer found!',
... routing_key='news.science',
... )
>>> # Delete exchange.
>>> bound_exchange.delete()
Queue¶
Example creating a queue using our exchange in the Exchange
example:
>>> science_news = Queue('science_news',
... exchange=news_exchange,
... routing_key='news.science')
For now science_news is just a declaration, you can’t perform actions on it. It just describes the name and options for the queue.
The queue can be bound or unbound. Bound means the queue is associated with a channel and operations can be performed on it. To bind the queue you call the queue instance with the channel as an argument:
>>> bound_science_news = science_news(channel)
Now you can perform operations like declare()
or purge()
:
>>> bound_science_news.declare()
>>> bound_science_news.purge()
>>> bound_science_news.delete()