Source

amqpev / examples / json_message.py

from __future__ import with_statement

import sys
from pprint import pprint

import amqpev.api as mq
import eventlet.api as ev
from eventlet.coros import metaphore


def main():

    service_factory = mq.BrokerServiceFactory('mq.local')

    try:
        round_trip(service_factory)
    finally:
        service_factory.close()


def round_trip(svc_f):
    with svc_f() as svc:
        json_q = svc.queue()
        json_q.publish(mq.JSONMessage(sys.path))

        with svc.consume_from(json_q) as cs:
            message = cs.next_message()
            pprint(message.body)

if __name__ == '__main__':
    main()