AMQP usage examples

Receiving messages from queues

No programming is needed to receive messages from AMQP queues. Create a new AMQP channel and a given service will be invoked for each message taken off a queue. The request will be in self.request.payload.

1
2
3
4
5
from zato.server.service import Service

class MyService(Service):
    def handle(self):
        self.logger.info('Got message: {}'.format(self.request.payload))

Sending messages to exchanges

Create a new outgoing AMQP connection and send a message like in the example below. The full API allows to set or override custom headers and properties.

1
2
3
4
5
from zato.server.service import Service

class MyService(Service):
    def handle(self):
        self.outgoing.amqp.send('my-message', 'outconn-name', '/exchange', 'route-key')