RabbitMQ Plugin

The plugin provides the ability to publish messages to RabbitMQ and read them from a queue.

Installation

  1. Copy the below line to dependencies section of the project build.gradle file

    Please make sure to use the same version for all VIVIDUS dependencies.
    Example 1. build.gradle
    implementation('org.vividus:vividus-plugin-rabbitmq')
  2. If the project was imported to the IDE before adding new dependency, re-generate the configuration files for the used IDE and then refresh the project in the used IDE.

Properties

Define one property group per connection. Pick a broker key (the first segment after rabbitmq.); use the same name as $brokerKey in the steps.

The broker key must not contain dots.
Property name Acceptable values Default Description

rabbitmq.<broker-key>.host

hostname or IP

localhost

The broker host.

rabbitmq.<broker-key>.port

port number

5671

The broker port.

rabbitmq.<broker-key>.username

string

The username.

rabbitmq.<broker-key>.password

string

The password.

rabbitmq.<broker-key>.virtual-host

string

The logical broker namespace (vhost) for connections, exchanges, and queues.

rabbitmq.<broker-key>.use-ssl

true / false

false

Enables an encrypted (TLS) connection to the broker.

Example 2. Local connection
rabbitmq.local.host=localhost
rabbitmq.local.port=5672
rabbitmq.local.username=guest
rabbitmq.local.password=guest
rabbitmq.local.virtual-host=/
Example 3. Hosted broker
rabbitmq.cloudamqp.host=penguin.lmq.cloudamqp.com
rabbitmq.cloudamqp.port=5672
rabbitmq.cloudamqp.username=bob
rabbitmq.cloudamqp.password=023fc15b9733b17df187
rabbitmq.cloudamqp.virtual-host=bob

Steps

Set message properties

Sets the AMQP message properties to be applied to the next published message. The properties are consumed after publishing and do not carry over to subsequent publish steps.

When I set RabbitMQ message properties:$properties
  • $properties - The message properties table. The table must contain exactly one row. Column names map directly to the writable properties of MessageProperties, for example contentType, contentEncoding, correlationId, replyTo, expiration, messageId, type, userId, appId.

Example 4. Publish a JSON message with a correlation ID
When I set RabbitMQ message properties:
|contentType     |correlationId|
|application/json|req-42       |
When I publish message `{"key":"value"}` with routing key `my-queue` to RabbitMQ broker `local`

Publish message

Sends the message text to the broker. The routing key is usually the queue name when you publish straight to a queue.

When I publish message `$message` with routing key `$routingKey` to RabbitMQ broker `$brokerKey`
  • $message - The message body.

  • $routingKey - The routing key (often the queue name).

  • $brokerKey - The broker key from the properties.

When I publish message `hello` with routing key `my-queue` to RabbitMQ broker `cloudamqp`

Retrieve message

Waits up to the timeout for one message on the given queue, stores the payload in a variable as text.

When I retrieve message from queue `$queue` of RabbitMQ broker `$brokerKey` with `$timeout` timeout and save it to $scopes variable `$variableName`
When I retrieve message from queue `orders.queue` of RabbitMQ broker `local` with `PT10S` timeout and save it to SCENARIO variable `last-order`
Then `${last-order}` is equal to `order-123`