New in version 2.8.
count
, messages from a RabbitMQ queue.The below requirements are needed on the local master node that executes this lookup.
Parameter | Choices/Defaults | Configuration | Comments |
---|---|---|---|
count
-
|
How many messages to collect from the queue.
If not set, defaults to retrieving all the messages from the queue.
|
||
queue
-
/ required
|
The queue to get messages from.
|
||
url
-
/ required
|
An URI connection string to connect to the AMQP/AMQPS RabbitMQ server.
For more information refer to the URI spec https://www.rabbitmq.com/uri-spec.html.
|
Note
vars
may result in unexpected results as the lookup is evaluated every time the variable is referenced.- name: Get all messages off a queue
debug:
msg: "{{ lookup('rabbitmq', url='amqp://guest:guest@192.168.0.10:5672/%2F', queue='hello') }}"
# If you are intending on using the returned messages as a variable in more than
# one task (eg. debug, template), it is recommended to set_fact.
- name: Get 2 messages off a queue and set a fact for re-use
set_fact:
messages: "{{ lookup('rabbitmq', url='amqp://guest:guest@192.168.0.10:5672/%2F', queue='hello', count=2) }}"
- name: Dump out contents of the messages
debug:
var: messages
Common return values are documented here, the following are the fields unique to this lookup:
Key | Returned | Description | |
---|---|---|---|
_list
list
|
A list of dictionaries with keys and value from the queue.
|
||
content_type
string
|
The content_type on the message in the queue.
|
||
delivery_mode
string
|
The delivery_mode on the message in the queue.
|
||
delivery_tag
string
|
The delivery_tag on the message in the queue.
|
||
exchange
string
|
The exchange the message came from.
|
||
headers
dictionary
|
The headers for the message returned from the queue.
|
||
json
dictionary
|
If application/json is specified in content_type, json will be loaded into variables.
|
||
message_count
string
|
The message_count for the message on the queue.
|
||
msg
string
|
The content of the message.
|
||
redelivered
boolean
|
The redelivered flag. True if the message has been delivered before.
|
||
routing_key
string
|
The routing_key on the message in the queue.
|
Hint
If you notice any issues in this documentation you can edit this document to improve it.