JMS WebSphere MQ usage examples

Receiving messages from queues

No programming is needed to receive messages from JMS WebSphere MQ queues. Create a new channel and a given service will be invoked for each message taken off a queue. The request, stripped off the MQRFH2 JMS headers, 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 queues

Create a new outgoing JMS WebSphere MQ connection and send a message like in the example below.

The full API allows to set or override custom headers and properties.

MQRFH2 JMS headers are added by Zato and from a receiving side everything seamlessly appears as though Zato was a Java application.

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

class MyService(Service):
    def handle(self):
        self.outgoing.jms_wmq.send('my-message', 'outgoing-connection-name', 'QUEUE.1')