> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stackshift.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# Consumers and Function consumers

> Each queue has one consumer: a Function, an HTTPS endpoint, or pull. Function consumers are chosen in the dashboard or API, not in code.

> [!TIP]
>
> **Live.** This area is documented as current, user-reliable behavior.

## Goal

Choose and set the consumer for a queue.

## Prerequisites

* A queue
* For a Function consumer, a project with Functions deployed

## Workflow

**Step 1**

Open the queue and choose Consumer.

**Step 2**

Pick Function, HTTPS push or Pull.

**Step 3**

For a Function, pick the project and the function path.

**Step 4**

Set batch size, batch wait, max retries, retry delay, concurrency and the dead-letter queue.

**Step 5**

Save. Delivery starts with the next batch.

## Function consumer

Pick the Function by its path in the dashboard, or pass function\_path (and function\_project\_id if it lives in another project) in the consumer settings. Nothing in the Function's code names the queue.

The Function receives the same batch object an HTTPS push consumer gets and returns the same reply shape: ack and retry lists, or nothing to ack the whole batch. Any message not listed in retry is acked. Throwing retries the whole batch.

```json Batch the Function receives theme={null}
{
  "queue": { "id": "q_7Hk2", "name": "orders" },
  "messages": [
    {
      "id": "msg_4fT9aQ2mZx1L",
      "body": { "order_id": "ord_123" },
      "content_type": "json",
      "attempts": 1,
      "sent_at": "2026-12-04T10:00:00Z"
    }
  ]
}
```

```ts api/orders-consumer.ts theme={null}
export default async function handler(batch) {
  const ack = []
  const retry = []
  for (const message of batch.messages) {
    try {
      await fulfil(message.body)
      ack.push(message.id)
    } catch {
      retry.push({ id: message.id, delay_seconds: 60 })
    }
  }
  return { ack, retry }
}
```

## Consumer settings

* kind: function, https or pull.
* batch\_size: 1 to 100 messages per batch.
* batch\_wait\_ms: how long to wait to fill a batch before sending a smaller one.
* max\_retries: up to 100 retries after the first delivery, so 3 means up to 4 deliveries. After that the message goes to the dead-letter queue, or is deleted if there is none.
* retry\_delay\_seconds: how long a retried message waits before it is delivered again.
* max\_concurrency: 0 for auto (scales with backlog), or a cap from 1 to 250 batches in flight.
* dead\_letter: \{mode: "new"} creates a dead-letter queue, \{mode: "existing", queue\_id} uses one you have, \{mode: "none"} deletes messages after max retries.

```bash CLI theme={null}
stackshift queues consumer set orders --consumer function --function-path api/orders-consumer --max-retries 3 --dead-letter orders-dlq
stackshift queues consumer set orders --consumer https --url https://app.example.com/queues/orders
stackshift queues consumer remove checkout-api:orders
```

```bash PUT /api/v1/queues/{queue}/consumer theme={null}
curl -X PUT https://api.stackshift.cloud/api/v1/queues/orders/consumer \
  -H "Authorization: Bearer $STACKSHIFT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"kind": "function", "function_path": "api/orders-consumer", "batch_size": 10, "batch_wait_ms": 5000, "max_retries": 3, "retry_delay_seconds": 30, "max_concurrency": 0, "dead_letter": {"mode": "new"}}'
```

## Remove a consumer

DELETE /queues/\{queue}/consumer removes it. Messages stay on the queue until a new consumer takes them or retention ends.

## Expected result

> [!TIP]
>
> The queue state is Active and the out rate rises as the consumer acks messages.

## Common failures

> [!WARNING]
>
> * The function path does not exist in the chosen project: deploy it first, then save the consumer again.
> * The consumer keeps failing: the queue page shows the last error and when it happened; recent failures list each retried batch and dead-lettered message.

## Related guides

> [card] [HTTPS push consumers](https://docs.stackshift.cloud/queues/https-push-consumers.md)
>
> StackShift POSTs each batch to your HTTPS endpoint, signed with Ed25519. Your reply says which messages to ack and which to retry.

> [card] [Pull consumers](https://docs.stackshift.cloud/queues/pull-consumers.md)
>
> A worker anywhere pulls a batch over HTTP, leases the messages for a visibility timeout, then acks or retries each one by lease id.

> [card] [Batching, retries and delays](https://docs.stackshift.cloud/queues/batching-retries-and-delays.md)
>
> How batch size and wait, retries, retry delays, concurrency and delivery guarantees work.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.