• Distributed Message Service

dms
  1. Help Center
  2. Distributed Message Service
  3. API Reference
  4. APIs for Managing Queues and Messages
  5. Sending Messages to a Queue

Sending Messages to a Queue

Function

This API is used to send messages to a queue. Multiple messages can be sent at the same time. The following requirements must be met:

  • A maximum of 10 messages can be sent at a time.
  • The aggregated size of messages sent at a time cannot exceed 512 KB.
  • In Kafka queues, messages are retained for 1 to 72 hours, depending on what you choose when creating a queue. In the other queues, messages are retained for at least 72 hours and will be deleted after expiry.

URI

URI format: POST /v1.0/{project_id}/queues/{queue_id}/messages

Table 1 describes the parameters of this API.

Table 1 Parameter description

Parameter

Type

Mandatory or Not

Description

project_id

String

Yes

Indicates the ID of a project.

queue_id

String

Yes

Indicates the queue ID.

Request

Request parameters

Table 2 and Table 3 list the parameter description.

Table 2 Request parameter

Parameter

Type

Mandatory or Not

Description

messages

Array

Yes

Indicates the message list.

returnId

Boolean

No

Indicates whether to return a message ID after a message is sent successfully. The default value is false. A message ID is returned only if the value is set to true.

Table 3 messages parameter description

Parameter

Type

Mandatory or Not

Description

body

JSON

Yes

Indicates the message body.

attributes

JSON object

No

Indicates the list of attributes, including attribute names and values.

The attribute name must be unique for a message.

Example request

{
    "messages" : [{
            "body" : "TEST11",
            "attributes" : {
                "attribute1" : "value1",
                "attribute2" : "value2"
            },
        }, {
            "body" : {
                "foo" : "test02"
            },
            "attributes" : {
                "attribute1" : "value1",
                "attribute2" : "value2"
            },
                    }
    ]
}

Response

Response parameters

Table 4 and Table 5 describe the response parameters.

Table 4 Parameter description

Parameter

Type

Description

message

JSON object

Indicates the message list.

Table 5 messages response parameter

Parameter

Type

Description

error

String

Indicates the error information.

error_code

Integer

Indicates the error code (if any).

state

Integer

Indicates the message sending status.

0: Messages are successfully sent.

1: Messages failed to be sent. The error and error_code parameters indicate the cause of failure.

Example response

{
  "messages" : [{
      "error" : null,
      "error_code" : null,
      "state" : 0
    }, {
      "error_code" : null,
      "state" : 0,
      "error" : null
    }
  ]
}

Status Code

Table 6 lists the status code indicating that the operation is successful. For details about the status codes indicating that the operation fails, see Status Code.

Table 6 Status code

Status Code

Description

201

Messages are sent successfully.