AMQP outgoing connections

Overview

Asynchronously sends a message to an AMQP exchange using connection parameters specified.

The message is first published on the Zato broker off of which the connector process responsible for communication with this particular AMQP broker picks it up and actually sends it to the remote exchange.

Note that the connection to the broker is initialized in a lazy fashion, it will be established the first time it’s needed.

The underlying client AMQP library is Kombu.

API

self.outgoing.amqp.send

send(msg, out_name, exchange, routing_key, properties={}, headers={}):

Uses an outgoing connection of a given name to send a message to an AMQP exchange under a provided routing key.

Parameters:
  • msg (string) – Message to send
  • out_conn (string) – Outgoing connection to use
  • exchange (string) – Name of an exchange to send the message to
  • routing_key (string) – Name of a routing key, if any should be used
  • properties (dict) –

    A dictionary, possibly empty, of additional properties to send along with the message body. Each property takes precedence over any one set in the connection template.

    Supported keys are:

    • content_type
    • content_encoding
    • delivery_mode
    • priority
    • expiration
    • user_id
    • app_id
    • correlation_id
    • cluster_id

    Consult AMQP docs for more information on how to use them.

  • headers (dict) – A dictionary, possibly empty, of extra headers to be sent along with the messages. If not specified manually, Zato will send X-Zato-Component and X-Zato-Msg-TS headers to indicate where the message originated from and when it was. The latter is in UTC.
Return type:

(None)

Usage example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
from zato.server.service import Service

class MyService(Service):
    def handle(self):

        # Request parameters
        msg = 'Hello AMQP broker!'
        out_name = 'CRM1'
        exchange = 'CRM1'
        routing_key = ''
        properties = {'app_id': 'ESB'}
        headers = {'X-Foo': 'bar'}

        # Send a message to the broker
        self.outgoing.amqp.send(msg, out_name, exchange, routing_key,
            properties, headers)

We can now observe that a message sent to the CRM1 exchange ..

../../_images/outconn-amqp-exch.png

went straight to the queue bound to the exchange - named CRM1 as well.

../../_images/outconn-amqp-queue.png