Enqueue

Adds an item to a queue or a message queue.

Command availability: IBM RPA SaaS and IBM RPA on premises

Description

Adds an item to a queue or message queue. A queue is a linear data structure, where the first items added are the first ones to be processed.

This command supports 7 Queue providers and a local queue, which only accepts a message queue collection.

Script syntax

IBM RPA's proprietary script language has a syntax similar to other programming languages. The script syntax defines the command's syntax in the script file. You can work with this syntax in IBM RPA Studio's Script mode.

enqueue --collection(Queue<Variant>) [--isserver(Boolean)] [--priority(Numeric)] [--correlationid(String)] --value(Variant)

Input parameter

The following table displays the list of input parameters available in this command. In the table, you can see the parameter name when working in IBM RPA Studio's Script mode and its Designer mode equivalent label.

Designer mode label Script mode name Required Accepted variable types Description
Queue collection Required Queue Queue in which the item is inserted.
Queue Provider isserver Optional Boolean Enable to enqueue when using a Queue provider and not a local queue.
Priority priority Only when Queue Provider is True Number Priority for each item to be enqueued.
Correlation Identifier correlationid Only when Queue provider is True Text Identifier responsible for grouping items with the same ID. Each provider has its own rule on how to interpret the IDs. See Example 3 to understand how this parameter is used.
Inserted Item value Required Any Item that should be inserted in the collection.

The inserted item must be of the same type as the items in the collection from the Queue parameter.

priority parameter options

Queue Provider Description
Active Message Queue In ActiveMQ, the range of values is 0 to 9, 0 being the lowest priority. By default, the priority queue is disabled.
Azure Queue Storage Azure queue storage does not provide a queue mechanism that natively supports automatic priorization of messages through sorting. When using Azure Queue Storage as the provider, you must leave this field blank. As an alternative, you can use multiple queues, one for high priority messages, and one for low-priority messages.
IBM MQ In IBM MQ, the supported values range from 0 to 9, where 0 is the lowest priority. The default value is 0.
Java Message Queue In Java Message Queue, the supported values range from 0 to 9, where 0 is the lowest priority. The default value is 4.
Microsoft Message Queue In Microsoft Message Queue, the supported values range from 0 to 7. The default value is 3.
Rabbit Message Queue n RabbitMQ, the supported values range from 0 to 255, where 0 is the lowest priority. The recommended range to use here is 1-10. The default value is 0.

Example

Example 1: The Enqueue command inserts the item "John" at the last position of a "Queue" type collection.

defVar --name namesCollection --type Queue --innertype String --value "[Ana,Mary,Lucas,Victor]"
enqueue --collection "${namesCollection}" --value John
logMessage --message "${namesCollection}" --type "Info"
// The obtained result in "namesCollection" is: [Ana,Mary,Lucas,Victor,John].

Example 2: After obtaining a connection to the queue provider Active MQ connection, and also the "Message Queue" type variable through the Get Queue command, the Enqueue command inserts the item "Mary" at the last position of that queue.

defVar --name connection --type QueueConnection
defVar --name obtainedQueue --type MessageQueue
connectActiveMQ --queueprovider Training --fromconfiguration  connection=value
getQueue --connection ${connection} --fromconfiguration  --queue queueA obtainedQueue=value
enqueue --collection "${obtainedQueue}" --isserver  --priority 1 --value Mary

Example 3: After obtaining a connection to the queue provider Active MQ connection, and also the "Message Queue" type variable through the Get Queue command, the Enqueue command inserts 4 names in the queue. Some of these names, have a correlation ID which groups the items with the same IDs. Then, the command removes the first item from the queue which is "Mary", but due to the priority parameter, "John" is the removed name.

defVar --name connection --type QueueConnection
defVar --name obtainedQueue --type MessageQueue
defVar --name correlationID --type String --value names
defVar --name success --type Boolean
defVar --name retrievedName --type QueueMessage
connectActiveMQ --queueprovider Training --fromconfiguration  connection=value
getQueue --connection ${connection} --fromconfiguration  --queue queueA obtainedQueue=value
enqueue --collection "${obtainedQueue}" --isserver  --priority 6 --correlationid "${correlationID}" --value Mary
enqueue --collection "${obtainedQueue}" --isserver  --priority 3 --value Felix
enqueue --collection "${obtainedQueue}" --isserver  --priority 1 --correlationid "${correlationID}" --value John
enqueue --collection "${obtainedQueue}" --isserver  --priority 9 --correlationid names --value Emilly
peek --collection "${obtainedQueue}" success=success retrievedName=value
logMessage --message "Name retrieved from the queue: ${retrievedName}" --type "Info"