This release is a pre-release and may not be stable for production use.
Overview
zamqp is aimed to broadcast messages and trigger events between python instances via AMQP.
It is based on amqplib and provides consumer and producer implementations as well as a mechanism to trigger zope events remotely.
Helper Classes
Create properties for AMQP connection.
>>> from zamqp import AMQPProps >>> props = AMQPProps(host='localhost', ... user='guest', ... password='guest', ... ssl=False, ... exchange='zamqp.broadcast.fanout', ... type='fanout', ... realm='/data')
Create AMQP connection manually.
>>> from zamqp import AMQPConnection
>>> connection = AMQPConnection('zamqp_queue', props)
Access connection channel.
>>> connection.channel
Consumer and producer
Create consumer callback.
>>> def callback(message): ... pass # do anything with received message here
Create and start consumer thread.
>>> from zamqp import AMQPConsumer
>>> from zamqp import AMQPThread
>>> consumer = AMQPConsumer('zamqp_queue', props, callback)
>>> thread = AMQPThread(consumer)
>>> thread.start()
Create producer and send a messages. Every python object which is serializable can be used as a message.
>>> from zamqp import AMQPProducer
>>> producer = AMQPProducer('zamqp_queue', props)
>>> message = 'foo'
>>> producer(message)
Trigger events
Create an event which should be triggered in the remote instance.
>>> class MyEvent(object): ... def __init__(self, name): ... self.name = name
Create a listener for MyEvent. This gets called when AMQP events are received.
>>> def my_listener(event): ... if not isinstance(event, MyEvent): ... return ... # do something >>> import zope.event >>> zope.event.subscribers.append(my_listener)
The default AMQPEventCallback just calls zope.event.notify with the received payload, which is the serialized event, in this case an instance of MyEvent.
Start our AMQP consumer for events.
>>> exchange = 'zamqp.events.fanout' >>> queue = 'zamqp_events' >>> from zamqp import AMQPEventCallback >>> props = AMQPProps(exchange=exchange) >>> callback = AMQPEventCallback() >>> consumer = AMQPConsumer(queue, props, callback) >>> thread = AMQPThread(consumer) >>> thread.start()
Trigger MyEvent to AMQP channel. The previously started event consumer now receives this event and triggers it locally in it’s own interpreter.
>>> from zamqp import AMQPEvent
>>> event = AMQPEvent(queue, props, MyEvent('myevent'))
>>> zope.event.notify(event)
Credits
-Robert Niederreiter <rnix@squarewave.at>
Changes
1.0b1
make it work [rnix]
Metadata
Release files for zamqp 1.0b1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| zamqp-1.0b1.tar.gz | 4.7 kB | Without provenance | Details for zamqp-1.0b1.tar.gz |
Release files / zamqp-1.0b1.tar.gz
| Download URL | zamqp-1.0b1.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3cb9f5645fdad0d84b838dda298d97f2070169aadcac638f74c965dffb9841d9
|
|
BLAKE2b-256 checksum How to use checksums |
7b4fabb83335b9478b51eb3db5fbe49274052aaeb414d718b9136ca2399fd467
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for zamqp 1.0b1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.