# Watch the queue before it backs up.

> Get a push the moment a message queue backs up. Pocket Alert turns RabbitMQ or SQS depth and consumer lag into an alert on your phone in under a second.

<!-- source: https://pocketalert.app/use-cases/queue-monitoring-alerts -->

A backed-up queue is easy to miss until messages pile up and users feel the delay. Have a small cron check read the depth with redis-cli, rabbitmqctl, or the AWS CLI and call Pocket Alert, and a stalled worker lands on your phone in under a second.

## Three steps to queue alerts

1. **Measure the queue** — Read the queue depth in a cron script with redis-cli LLEN, rabbitmqctl, or the AWS CLI.
2. **Fire on threshold** — Call pocketalert send (or curl the messages API) when depth crosses your threshold.
3. **Act in time** — Your phone buzzes within a second. Drain the backlog before users notice.

## Catch the backlog while it is small

A one-line depth check in cron calls Pocket Alert. It turns a number you would never watch into a push notification you can act on.

- **Depth thresholds** — A threshold in your cron script fires the alert once depth drifts past the line you set.
- **Stall detection** — A runaway backlog or a fully stalled consumer sends a push while a brief blip stays under the line.
- **Depth in the message** — Drop the queue name and current depth straight into the title and message of the call.
- **Any broker** — redis-cli LLEN, rabbitmqctl list_queues, and the AWS CLI for SQS all return a number you can send on.
- **Per-queue channels** — Each queue gets its own application_id, so payments and email never blur together.
- **Sub-second delivery** — The push lands in under a second, fast enough to act before the backlog snowballs.

## Alert on a backed-up queue

### Redis list depth (LLEN)

A tiny cron script reads the depth and calls the CLI once it crosses your threshold:

```
* * * * * depth=$(redis-cli LLEN queue:emails); \
  [ "$depth" -gt 10000 ] && pocketalert send \
    -t "Queue backed up" -m "emails: $depth pending"
```

### RabbitMQ queue length

```
* * * * * depth=$(rabbitmqctl list_queues -p / name messages | awk '$1=="emails"{print $2}'); \
  [ "$depth" -gt 10000 ] && pocketalert send \
    -t "Queue backed up" -m "emails: $depth messages"
```

### SQS approximate depth via the API

```
depth=$(aws sqs get-queue-attributes --queue-url "$QUEUE_URL" \
  --attribute-names ApproximateNumberOfMessages \
  --query 'Attributes.ApproximateNumberOfMessages' --output text)
[ "$depth" -gt 10000 ] && curl -X POST "https://api.pocketalert.app/v1/messages" \
  -H "Token: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"title\":\"Queue backed up\",\"message\":\"orders: $depth pending\",\"level\":\"critical\"}"
```

Give each queue its own `application_id` so payments and email land in separate channels. The [docs](https://info.pocketalert.app/getting-started.html) cover targeting and per-application channels.

## FAQ

### How do I get alerts for a backed-up queue?

Run a small cron script that reads the queue depth and calls `pocketalert send` (or curls the messages API) when it crosses your threshold. Works with Redis `LLEN`, RabbitMQ `list_queues`, and SQS `ApproximateNumberOfMessages`.

### Can I separate a real stall from a brief backlog?

Set the threshold in the script. A short, recoverable backlog never crosses the line, so only a genuine stall or a runaway depth sends a push notification.

### Which brokers can I read the depth from?

Any broker you can query from the shell works. `redis-cli LLEN queue:emails`, `rabbitmqctl list_queues`, or the AWS CLI for SQS all return a number you can compare and send on.

### How does the queue name and depth show up?

Put the queue name and the current depth straight into the title and message of the call, so the push reads `emails: 18420 pending` with no extra glue code.

### Can I split alerts per queue or service?

Pass a different `application_id` per queue. The emails queue and the payments worker land in separate channels, so you read the alert and know where to look.

### Can a stalled queue alert break through silent mode?

Yes. Give the alert `level=critical` and Android posts it on a channel that bypasses Do Not Disturb, while iPhone shows it as a time-sensitive notification that breaks through Focus. If you also push routine depth reports, send those with `level=silent` so they land in history without a buzz.
