This how-to shows what is needed to send AMQP messages to exchanges using Zato, which is a Python-based ESB for SOA, cloud integrations and backend services.
SHOW ME THE CODE
This is the code needed:
Read below for the whole story.
UNDERSTANDING CONNECTION DEFINITIONS VS. CONNECTIONS
Before sending a first message, you need to make it known to Zato where messages will be sent as by default Zato encourages separation between services producing messages and the concrete destinations where the messages arrive.
You only invoke a single .send method in your code, without actually specifying particular URLs or credentials, message expiration, content type and so on. You can, but you don't have to.
That all is achieved by means of connection definitions and actual connections. A connection definition is a template describing details of connecting to an AMQP broker - its network address, virtual host, username/password and similar. Each connection definition can be used to create one or more connections that deal with particulars of each message sent - its priority, delivery mode and other per-message information.
Both types of objects are created using Zato's GUI or other means, such as enmasse or API.
First create a connection definition and then use it to create an outgoing connection, as in the screenshots below.
And that concludes it - a new connection has been created and the code shown before can be now hot-deployed in order to send AMQP messages.
OTHER MEANS OF CONFIGURATION
Instead, or in addition to, enmasse tool and API can be also used to create, list, update or delete AMQP connections. You're not limited to the GUI only.
This is a feature that will be added in much a broader scope - along with GUI, API and more usage examples - in next releases, but for 1.1, a zato-labs project is provided to support an invoke/retry pattern.
This can be used to implement any of these scenarios
invoke a service synchronously and if it fails, repeat the invocation a configured number of times waiting blockingly for the response
invoke a service synchronously and if it fails, invoke the service asynchronously in background notifying a callback service when it's finished, successfully or not
invoke a service asynchronously in background, and if it fails, repeat the invocation a configured number of times notifying a callback service when it's finished, successfully or not
Install the add-on by putting it on PYTHONPATH, for instance, using pip and linking it to zato_extra_paths as below. This is a change that needs a server restart.
You can now make use of invoke/retry as in the code examples below.
As an ending note, this feature is a good example of Zato's extensibility. No changes were needed to support it and only publically available features and API were used to add new value on top of existing core platform.