Tutorial on sending AMQP messages using Python Zato, zatoamqp
This help topic shows the content required to use Zato to send AMQP messages. Zato is an enterprise service bus (ESB) for SOA, cloud integration, and backend services based on Python ).
Code demo
The following code is required:
From zato. server. service import Service
Class MyService (Service ):
Def handle (self ):
Msg = 'my message'
Conn_name = 'my CRM connection'
Exchange_name = 'my exchange'
Routing_key =''
Self. outgoing. amqp. send (msg, conn_name, exchange_name, routing_key)
Understanding connection definition and Connection
Before sending the first message, you must let Zato know where to send the message, because Zato supports separating the service that generates the message from the actual destination of the message delivery by default.
In your code, you only call a single. send method. You do not need to specify a specific URL or credential, message expiration time, content type, and so on. You can specify these parameters, but you do not need them.
All of this is achieved through connection definitions and real connections. The connection definition is a template that describes the details required to connect to the AMQP proxy-the proxy's network address, virtual host name, user name/password, and similar things. Each connection definition can be used to create one or more details-message priority, distribution mode, and other connections for processing the message to be sent.
The two object types can be created using the Zato GUI, or by using other methods such as enmasse or API.
Graphic Interface
Create a connection definition and use it to create an external connection, as shown in:
All in all, after creating a new connection and writing a piece of code as shown above, you can hot deploy it to send AMQP messages.
Other configuration methods
On the contrary, you can also create, list, update, or delete AMQP connections by using the enmasse tool and API. It is not limited to graphical interfaces.
More examples
For more examples of using AMQP, see here.