ZeroMQ usage examples

Receiving messages from queues

No programming is needed to receive messages from ZeroMQ sockets. Create a new ZeroMQ channel and a given service will be invoked for each message taken from a socket. 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 sockets

Create a new outgoing ZeroMQ connection and send a message like in the example below.

The API is documented here.

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

class MyService(Service):
    def handle(self):
        self.outgoing.zmq.send('my-message', 'outconn-name')