--- alias: user-guide-automation-task-retrievefromqueue tags: - automation tasks description: "This task retrieves data from a persistent queue based on specified management rules, emitting a value or default if empty" --- # Retrieve Data From Queue :iot-retrieve-data-lg: This task retrieves a value from a persistent queue based on a specified queue management type (FIFO, LIFO, or FEFO). If the queue is empty, a default value can be provided and emitted. ![Retrieve From Queue Workflow Task](../images/tasks_queue_retrieve.png) ## Inputs | Name | Data Type | Description | |---------------|-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | Queue Name | `String` | The name of the persistence queue to retrieve data from. | | Queue Type | `String` | The type of queue management to use for retrieval. Possible values are `FIFO` (First-In, First-Out), `LIFO` (Last-In, First-Out), and `FEFO` (First-Expired, First-Out - requires messages to have an expiration timestamp). Defaults to `FIFO`. If an invalid type is provided, it will fall back to `FIFO`. | | Default Value | `any` | The value to emit on the `Value` output if the specified queue is empty when retrieval is attempted. | | Activate | `any` | When this input transitions to a truthy value, the task attempts to retrieve a value from the specified `Queue Name` using the selected `queueType`. | ## Outputs | Name | Data Type | Description | |---------|-----------|-----------------| | Value | `any` | Emits the value retrieved from the queue. If the queue is empty and a `Default Value` is provided, that value will be emitted instead. | | Success | `Boolean` | Emits `true` when a value is successfully retrieved from the queue (or the `Default Value` is emitted if the queue is empty). | | Error | `Error` | Emits an `Error` object if any issue occurs during the retrieval process, such as an invalid queue name or an error accessing the data store. | ## Settings On the General Tab, you have the usual general settings and the following settings: | Name | Data Type | Default | Description | Values | | --------------------- | --------- | ------- | ---------------------------------------------------------------------------------- | ------ | | Default Queue Name | `String` | No | Default persistence queue name to retrieve data from. | | | Default Queue Type | `String` | No | Default queue type to use for retrieval. Defaults to `FIFO`. | `FIFO`, `LIFO` or `FEFO` | | Default Value | `any` | No | The value to emit on the `Value` output if the specified queue is empty when retrieval is attempted. | | ## Behavior When the `Activate` input receives a `true` value, the task attempts to retrieve the next value from the queue specified by `Queue Name`, based on the `Queue Type`. * **FIFO (First-In, First-Out):** Retrieves the oldest value that was added to the queue. * **LIFO (Last-In, First-Out):** Retrieves the most recently added value to the queue. * **FEFO (First-Expired, First-Out):** Retrieves the oldest value that has an expiration timestamp that has passed. If no expired messages is found on the queue, then it will behave as FIFO (retrieves oldest item in the queue). If the specified `Queue Name` does not exist, the task will emit an error. If the queue exists but is empty when retrieval is attempted, the task will emit the value provided in the `Default Value` input on the `Value` output and `true` on the `success` output. If no `Default Value` is provided and the queue is empty, the `Value` output will emit `null` or `undefined`, and `success` will still be `true` (indicating a successful *attempt* to retrieve). If the provided `Queue Type` is not one of the valid options (`FIFO`, `LIFO`, `FEFO`), the task will log a warning and default to `FIFO` behavior for that retrieval attempt. Each time the `Activate` input is triggered, the task attempts to retrieve and remove a single value from the queue (except in cases where the queue is empty and the `Default Value` is used). ## Remarks * This task assumes that the queue has been previously created and populated by a task like "Store in Queue". * For the "FEFO" queue type to function correctly, the values stored in the queue should have associated expiration timestamps. If no item with expiration time is available in the queue then the oldest item in the queue is retrieved (mimics FIFO queue type behavior). * Consider the implications of the chosen `Queue Type` on the order in which values are processed from the queue, as this can significantly affect the workflow's logic.