Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install zamqp

How to install zamqp

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install zamqp
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
1.0b1 Available View build log
Windows (64-bit)
1.0b1 Available View build log
Mac OS X (10.5+)
1.0b1 Available View build log
Linux (32-bit)
1.0b1 Available View build log
Linux (64-bit)
1.0b1 Available View build log
 
License
GNU General Public Licence
Dependencies
Imports
Lastest release
version 1.0b1 on Jan 5th, 2011

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',

System Message: ERROR/3 (<string>, line 19)

Inconsistent literal block quoting.

... 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):

System Message: ERROR/3 (<string>, line 45)

Inconsistent literal block quoting.

... 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):

System Message: ERROR/3 (<string>, line 73)

Inconsistent literal block quoting.

... def __init__(self, name): ... self.name = name

Create a listener for MyEvent. This gets called when AMQP events are received.

>>> def my_listener(event):

System Message: ERROR/3 (<string>, line 81)

Inconsistent literal block quoting.

... 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]

Subscribe to package updates

Last updated Jan 5th, 2011

Download Stats

Last month:1

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.