# Queues

## General

Message queues provide an asynchronous communications protocol, meaning that the sender and receiver of the message do not need to interact with the message queue at the same time.

Message queues have implicit or explicit limits on the size of data that may be transmitted in a single message and the number of messages that may remain outstanding in the queue. Messages placed onto the queue are stored until the recipient retrieves them.

![Queues Message Pattern](https://2828835384-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M2b9dwAGbMPWty0fPGr%2F-M2cg-nL53EVg5rPnOZB%2F-M2chJWYS21IaKwHu5gG%2Fqueue.png?alt=media\&token=8c208d56-206b-4d3b-b80a-419cb97c3d28)

## Core Features

KubeMQ supports distributed durable FIFO based queues with the following core features:

* **Guaranteed Delivery** - At-least-once delivery and most messages are delivered exactly once.
* **Single and Batch Messages Send and Receive** - Single and multiple messages in one call
* **RPC and Stream Flows** - RPC flow allows an insert and pulls messages in one call. Stream flow allows single message consuming in a transactional way
* **Message Policy** - Each message can be configured with expiration and delay timers. Also, each message can specify a dead-letter queue for unprocessed messages attempts
* **Long Polling** - Consumers can wait until a message available in the queue to consume
* **Peak Messages** - Consumers can peek into a queue without removing them from the queue
* **Ack All Queue Messages** - Any client can mark all the messages in a queue as discarded and will not be available anymore to consume
* **Visibility timers** - Consumers can pull a message from the queue and set a timer which will cause the message not be visible to other consumers. This timer can be extended as needed.
* **Resend Messages** - Consumers can send back a message they pulled to a new queue or send a modified message to the same queue for further processing.

## Publish to Queue

### Publish Single and Batch Messages

KubeMQ allows the producer to send single and/or batch messages in one command.

#### Demo - Single

![](https://2828835384-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M2b9dwAGbMPWty0fPGr%2F-M2cg-nL53EVg5rPnOZB%2F-M2chOTGgsOpjqQFXPoo%2Fkubemqctl-queue-send-receive.gif?alt=media\&token=37b91c03-7c69-495f-bd47-5cc204cd0eca)

#### Demo - Batch

![](https://2828835384-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M2b9dwAGbMPWty0fPGr%2F-M2cg-nL53EVg5rPnOZB%2F-M2chOTFEKqw4LKKmaKM%2Fkubemqctl-queue-send-receive-batch.gif?alt=media\&token=86c80706-edcb-493f-a6d9-99ea74c052d7)

### Message Expiration (TTL)

KubeMQ allows the producer to set each message with an expiration time (in seconds) also known as Time To Live (TTL). After this time, the message will not be longer available to any consumer.

{% embed url="<https://player.vimeo.com/video/372196075>" %}

### Message Delay (Scheduled Messages)

KubeMQ allows the producer to set each message with sending delay (in seconds) time, also known as Scheduled Messages. Until this time, the message will not be available to and consumer.

{% embed url="<https://player.vimeo.com/video/372196064>" %}

### Dead-Letter Queues

KubeMQ allows a producer to set a dead-letter queue per each message a which the message will be moved onto in case of a consumer will fail to ack the message (such a poison message).

{% embed url="<https://vimeo.com/372196052>" %}

## Consume from Queue

### Long Polling

KubeMQ allows the consumer to connect to KubeMQ and wait for a specified time until a message is available in the queue to consume.

{% embed url="<https://vimeo.com/372196094>" %}

### Peek Queue Messages

KubeMQ allows a consumer to peek one or many messages in the queue without removing them from the queue.

{% embed url="<https://vimeo.com/372196106>" %}

### Ack All Queue Messages

KubeMQ allows a consumer to ack all messages in the queue (clean-up); therefore, existing messages in the queue will not be available anymore to consume.

![](https://2828835384-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M2b9dwAGbMPWty0fPGr%2F-M2cg-nL53EVg5rPnOZB%2F-M2chJWnzAQHxHENOqrO%2Fqueue-ack-all.png?alt=media\&token=d3bcce98-a21f-445a-8086-e3676c0489be)

{% embed url="<https://vimeo.com/372196028>" %}

### Message Visibility

KubeMQ allows the consumer to set a visibility time, which during this time, the message will not be available to any other consumer. During the visibility period, the consumer can extend the visibility time window at any time. Once the consumer completed the message processing, he sends an ack notification to the queue. If the consumer failed to ack the message during the visibility time, the message will be available back in the queue to consume by others.

#### Visibility With Ack

![](https://2828835384-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M2b9dwAGbMPWty0fPGr%2F-M2cg-nL53EVg5rPnOZB%2F-M2chJWdCW9QUpXSh-r7%2Fqueue-visibility-ack.png?alt=media\&token=6bcb023a-6041-430b-8e26-186ef03415ff)

#### Visibility With Failure

![](https://2828835384-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M2b9dwAGbMPWty0fPGr%2F-M2cg-nL53EVg5rPnOZB%2F-M2chJWbp6deF5glhwL-%2Fqueue-visibility-reject.png?alt=media\&token=5226d8da-e1b9-4cf0-bcfa-2e1415ba1718)

{% embed url="<https://vimeo.com/372196120>" %}

### Resend Message

KubeMQ allows the consumer to resend the current pulled message to a new queue without the need to send the actual message (act as producer).

![](https://2828835384-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M2b9dwAGbMPWty0fPGr%2F-M2cg-nL53EVg5rPnOZB%2F-M2chJWf16Nw9x6rWagf%2Fqueue-resend.png?alt=media\&token=cbb22e72-05a6-4208-8fd7-11b6c0c93ee9)

#### Demo

![](https://2828835384-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M2b9dwAGbMPWty0fPGr%2F-M2cg-nL53EVg5rPnOZB%2F-M2chOTAavVJ-q9xYQ8K%2Fkubemqctl-queue-stream-resend-queue.gif?alt=media\&token=0fbe9fd2-2ca8-403f-9e8b-325a27a9d89f)

### Resend Modified Message

KubeMQ allows the consumer to send back to the queue a modified message for further processing by other consumers.

![](https://2828835384-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M2b9dwAGbMPWty0fPGr%2F-M2cg-nL53EVg5rPnOZB%2F-M2chJWhfsuUkhZojOKZ%2Fqueue-resend-new.png?alt=media\&token=a5b16d8e-6d8b-4401-be6d-994dc4a58ca3)

#### Demo

![](https://2828835384-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M2b9dwAGbMPWty0fPGr%2F-M2cg-nL53EVg5rPnOZB%2F-M2chOTBCz4zSKGy4i_6%2Fkubemqctl-queue-stream-resend-new.gif?alt=media\&token=1d22c72b-f893-447c-80e4-4377862dbe41)

### Transactional Queue

KubeMQ allows the consumer to connect in a stream transactional model where the consumer can control the flow of message life-cycle.

#### Successful Flow

![](https://2828835384-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M2b9dwAGbMPWty0fPGr%2F-M2cg-nL53EVg5rPnOZB%2F-M2chJWcUEg2AJRAHDYW%2Fqueue-stream-flow-ok.png?alt=media\&token=007b716e-210f-478f-82bc-42b2787b8a42)

#### Failed Flow

![](https://2828835384-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M2b9dwAGbMPWty0fPGr%2F-M2cg-nL53EVg5rPnOZB%2F-M2chJWegw2zoTlR-qF4%2Fqueue-stream-flow-fail.png?alt=media\&token=5b78a1cd-4bd8-4d2d-ae39-1700092b68ad)
