# Send messages

Put a message on a queue, or up to ten in one request, with attributes, a delay, or a FIFO message group.

Replace _my-queue_ with the name of your queue.

A message has a body of text (not empty; no control characters other than tab, line feed and
carriage return) and up to 10 attributes, name–value string pairs whose names are letters, digits,
`_`, `.` or `-`. Its size is the body plus the attributes' names and values in UTF-8 bytes, and
must not exceed the queue's maximum message size (256 KiB on a new queue).

## Prerequisites

- Permission for `queue:SendMessage` on the queue. The batch send needs the same action. For the
  console, also `queue:GetQueueAttributes` on it, to open its page.

## Send a message

**Console**
1. Open the queue, then choose **Send and receive** (or **Send a message** at the top of the
   queue's page).
2. Under **Send a message**, for **Body**, enter the message.
3. (Optional) For **Attributes**, enter one `key=value` per line, up to ten.
4. On a standard queue, for **Delay**, enter the seconds before the message can be received (0 to
   900). The field starts at 0 and is always sent, so a console send does not use the queue's
   delivery delay unless you enter it here. On a FIFO queue, for **Message group**, enter the group, and for
   **Deduplication id**, enter an id (optional when the queue has content-based deduplication).
5. Choose **Send**.

The section shows `Sent` with the message id, and on a FIFO queue its sequence number. A FIFO send
that repeats a recent deduplication id shows `Duplicate of` the original message instead.

**CLI**
```sh
dcloud queue messages send my-queue --body '{"orderId": 42}' --attributes type=order.created
```

On a FIFO queue, add `--message-group-id` and, unless the queue has content-based deduplication,
`--message-deduplication-id`.

**API**
```http
POST /queue/api/queues/my-queue/messages
{ "body": "{\"orderId\": 42}", "attributes": { "type": "order.created" }, "delaySeconds": 10 }
```

The answer is `201` with `messageId`, `md5OfBody`, `sentAt`, `sequenceNumber` (FIFO only, else
`null`) and `duplicate`.

Up to 10 messages in one request, each with an `id` of your choosing, unique in the batch:

```http
POST /queue/api/queues/my-queue/messages/batch
{ "entries": [ { "id": "a", "body": "first" }, { "id": "b", "body": "second" } ] }
```

The answer is `201` with `successful` (one entry per message sent, with its `id`) and `failed`
(`id`, `code` and `error` for each entry not sent). An entry that fails on its own, for example
one too large for the queue, does not stop the others.

**Terraform:** not available. Sending a message is an action, not configuration.

To send from an SQS client, use `SendMessage` or `SendMessageBatch`; see
[Use an SQS client](use-an-sqs-client.md).

## Result

The message is stored and can be received once its delay, if any, has passed. A delay given with a
send overrides the queue's delivery delay for that message.

## When a send is refused

- `400` "Message is 70000 bytes; this queue accepts at most 65536." when the message is larger
  than the queue's maximum message size (here set to 64 KiB). In a batch, that entry fails alone.
- `400` "The batch is 300000 bytes; a batch may carry at most 262144." when the messages of one
  request together exceed 256 KiB, a single message over 256 KiB included. The whole batch is
  refused.
- `403` with code `OverLimit` when the queue would hold more than 100,000 messages, or your
  organization's queues more than 1 GiB of messages. The whole batch is refused. The counts are a
  few seconds old, so a burst can go slightly over before sends are refused. See
  [Quotas](quotas.md).
- `400` "MessageDeduplicationId applies only to FIFO queues." on a standard queue. A message group
  is ignored there.
- On a FIFO queue: `400` "The request must contain the parameter MessageGroupId." without a group;
  "DelaySeconds is not valid per message on a FIFO queue; set the delay on the queue instead."
  with a delay; and "The queue should either have ContentBasedDeduplication enabled or
  MessageDeduplicationId provided explicitly." without a deduplication id on a queue without
  content-based deduplication.

## Related

- [Receive and delete messages](receive-and-delete-messages.md)
- [FIFO queues](fifo-queues.md)
