在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):celery/kombu开源软件地址(OpenSource Url):https://github.com/celery/kombu开源编程语言(OpenSource Language):Python 99.5%开源软件介绍(OpenSource Introduction):kombu - Messaging library for Python
AboutKombu is a messaging library for Python. The aim of Kombu is to make messaging in Python as easy as possible by providing an idiomatic high-level interface for the AMQ protocol, and also provide proven and tested solutions to common messaging problems. AMQP is the Advanced Message Queuing Protocol, an open standard protocol for message orientation, queuing, routing, reliability and security, for which the RabbitMQ messaging server is the most popular implementation. Features
For an introduction to AMQP you should read the article Rabbits and warrens, and the Wikipedia article about AMQP. Transport Comparison
DocumentationKombu is using Sphinx, and the latest documentation can be found here: https://kombu.readthedocs.io/ Quick overviewfrom kombu import Connection, Exchange, Queue
media_exchange = Exchange('media', 'direct', durable=True)
video_queue = Queue('video', exchange=media_exchange, routing_key='video')
def process_media(body, message):
print(body)
message.ack()
# connections
with Connection('amqp://guest:guest@localhost//') as conn:
# produce
producer = conn.Producer(serializer='json')
producer.publish({'name': '/tmp/lolcat1.avi', 'size': 1301013},
exchange=media_exchange, routing_key='video',
declare=[video_queue])
# the declare above, makes sure the video queue is declared
# so that the messages can be delivered.
# It's a best practice in Kombu to have both publishers and
# consumers declare the queue. You can also declare the
# queue manually using:
# video_queue(conn).declare()
# consume
with conn.Consumer(video_queue, callbacks=[process_media]) as consumer:
# Process messages and handle events on all channels
while True:
conn.drain_events()
# Consume from several queues on the same channel:
video_queue = Queue('video', exchange=media_exchange, key='video')
image_queue = Queue('image', exchange=media_exchange, key='image')
with connection.Consumer([video_queue, image_queue],
callbacks=[process_media]) as consumer:
while True:
connection.drain_events() Or handle channels manually: with connection.channel() as channel:
producer = Producer(channel, ...)
consumer = Producer(channel) All objects can be used outside of with statements too, just remember to close the objects after use: from kombu import Connection, Consumer, Producer
connection = Connection()
# ...
connection.release()
consumer = Consumer(channel_or_connection, ...)
consumer.register_callback(my_callback)
consumer.consume()
# ....
consumer.cancel() Exchange and Queue are simply declarations that can be pickled and used in configuration files etc. They also support operations, but to do so they need to be bound to a channel. Binding exchanges and queues to a connection will make it use that connections default channel. >>> exchange = Exchange('tasks', 'direct') >>> connection = Connection() >>> bound_exchange = exchange(connection) >>> bound_exchange.delete() # the original exchange is not affected, and stays unbound. >>> exchange.delete() raise NotBoundError: Can't call delete on Exchange not bound to a channel. TerminologyThere are some concepts you should be familiar with before starting:
InstallationYou can install Kombu either via the Python Package Index (PyPI) or from source. To install using pip,: $ pip install kombu To install using easy_install,: $ easy_install kombu If you have downloaded a source tarball you can install it by doing the following,: $ python setup.py build # python setup.py install # as root Getting HelpMailing listJoin the `celery-users`_ mailing list. Bug trackerIf you have any suggestions, bug reports or annoyances please report them to our issue tracker at https://github.com/celery/kombu/issues/ ContributingDevelopment of Kombu happens at Github: https://github.com/celery/kombu You are highly encouraged to participate in the development. If you don't like Github (for some reason) you're welcome to send regular patches. LicenseThis software is licensed under the New BSD License. See the LICENSE file in the top distribution directory for the full license text. kombu as part of the Tidelift SubscriptionThe maintainers of kombu and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/pypi-kombu?utm_source=pypi-kombu&utm_medium=referral&utm_campaign=readme&utm_term=repo) -- |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论