This recipe demonstrates how to use Orchestrator as a producer and consumer of AMQP message queues, how to create a subscription, and how to use Orchestrator policies to react to messages in the queues.
If you are totally new to AMQP, I suggest you start reading the How it works... section first.
An AMQP broker such as RabbitMQ is required. You can download it from http://www.rabbitmq.com . You can find a fast and easy Windows installation and configuration for RabbitMQ in the There's more... section.
As with SOAP, REST, and a lot of other modules, we can actually use the provided workflows. So in the following sections, we will make use of them.
To start with AMQP, we first need to add an AMQP broker to Orchestrator:
TCP 5672
.
To work with AMQP, we need exchanges and queues, so we will define them now:
systemExchange
(this is used by vCloud Director).Now we will create a queue:
vco
.Now we will bind the queue to an exchange:
#
is a wildcard for everything).We will now send a message to the exchange:
We will now read the message we sent to the queue:
If you are new to AMQP, then I would suggest that you read the How it works... section at this stage, where an example of the value of all this is provided.
Subscribing to a queue means that Orchestrator can use a policy to monitor this queue continually for new messages:
vco
.You should be aware of how Orchestrator policies work; refer to the Working with policies section in Chapter 8, Better Workflows and Optimized Working.
10.06.1 AMQP Worker
.
10.6.3 Fill
, to fill up the queue with messages. Watch the logs in the policy to see the execution happening.A message bus such as RabbitMQ can be compared to a mail server that stores e-mails until they are taken off the server. The Advanced Message Queuing Protocol (AMQP) defines a publisher/producer as someone sending messages, a broker (server) as the storage and process host, and a client/consumer as someone who receives messages.
Any message that is sent to the broker will be put in an exchange. The exchange will use the routing key to route the message into a queue. A consumer will read messages from a queue.
AMQP uses a virtual host or vHost (nothing to do with virtualization), which defines authentications, which means that you can have different vHosts that provide access to different users, as you cannot give access rights to exchanges or queues.
Here is a simple example using Orchestrator (example workflows 10.06.1 AMQP Worker
and 10.6.2 Fill up and work
):
The example workflow 10.6.2 Fill up and work
will fill up the systemExchange
exchange from an attribute (an array of strings) using the #
routing key. The #
routing key will just forward everything into the vco
queue. It will then start the workflow example 10.06.1 AMQP Worker
twice asynchronously. Each of the Worker workflows will go and get a message from the queue, check whether the body is defined (not Null
), and then sleep one second for each letter in the message.
When you run the workflow, you will see how the two worker workflows grab the next message in the queue and work on it until the queue is empty.
To understand routing and exchanges, we need to explain the four different kinds of exchange:
Exchange type |
Description |
Direct |
This exchange routes messages, depending on their routing key, to a specific queue that is specified by the routing key in the exchange-queue binding. |
Fanout |
All messages sent to this exchange will be forwarded into all queues that are bound to it. |
Headers |
This ignores the routing key. It routes messages depending on the sender (as in, mail headers). |
Topics |
Routing is done using wildcards. There are two wildcards that AMQP understands: * means exactly one word and # means none to many words. |
Let's take a quick look at how to install and get AMQP going using RabbitMQ.
The following steps will install RabbitMQ on a Windows host and configure a user to connect from the outside. Please note that this is a quick-and-dirty installation and configuration that is only okay for labs; however, it gets beginners going:
TCP 5672
and 15672
are open in and outgoing.rabbitmq
-plugins enable rabbitmq_management
.http://localhost:15672
.guest
and the password is guest
.testuser
) as well as a password. Add the tag Admin and click on Add user.You are now able to connect from the outside to RabbitMQ and use it:
Check out the AMQP example that comes with vRO7.
AMQP basics:
There's a worthwhile article on how to use AMQP, vCloud Director, and Orchestrator together at:
http://www.vcoteam.info/articles/learn-vco/179-configure-the-amqp-plug-in.html .
The example workflows are as follows:
10.06.1 AMQP Worker
10.06.2 Fill up and work
10.06.3 Fill