Extending vCloud API with vCloud Extensibility Framework : Extension Example : 3.2 Handling Extension AMQP Messages
   
3.2 Handling Extension AMQP Messages
When the API receives an extension request, the vCloud Director REST service creates a message and sends it to the system AMQP service, specifying the exchange and routing key registered by the extension service. The extension service retrieves the message from a queue bound to the exchange it registered, processes the request, and returns a response to the common reply exchange.
To handle the AMQP messages, you must use a language that has a client to communicate with RabbitMQ. There are tutorials for most major programming languages on the RabbitMQ site at https://www.rabbitmq.com/tutorials/tutorial-one-go.html. This example uses Python with the Pika client.
To listen for incoming messages, you must bind to the correct Exchange and Queue (also referred to as RoutingKey). This was defined when you registered the extension (see Section 3.1, Register an Extension).
Exchange: vcdext
Queue: gcp-ticketing
When new messages are received, the following information is provided: channel, method, properties and body.
The properties contain three important pieces of information that are required to respond to the request:
Headers – These are the AMQP headers, not the API headers. The key piece of information required is the replyToExchange.
Correlation_id – vCloud Director sets a unique correlation_id in every message sent to the extension service, and the extension must set the same value in the corresponding response.
Reply_to – What queue to respond on.
The body is made up of many parts, but, for basic integration, the following is required:
Body – The body of the API request.
Headers – The API request headers. It is important to note the incoming Accept header to respond back with the correct content type.
Method – The method used to call the API (GET, POST, PUT, DELETE).
Id – The unique ID assigned to the incoming message. This is used to reply to the message.
For more information about the body, see the VMware vCloud API Programming Guide for Service Providers at http://pubs.vmware.com/vcd-80/topic/com.vmware.vcloud.api.sp.doc_90/GUID-DD339C3C-4304-4524-BD00-A76E47A9C731.html.