Sending Messages to a Queue
Function
This API is used to send messages to a queue. Multiple messages can be sent at a 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
POST /v1.0/{project_id}/queues/{queue_id}/messages
Table 1 describes the parameters of this API.
Request
Request parameters
Table 2 and Table 3 list the parameter description.
Parameter |
Type |
Mandatory |
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. |
Parameter |
Type |
Mandatory |
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. |
tags |
JSON object |
No |
Indicates the message label, which is used to identify message types. You can use message labels to filter the messages you want to retrieve from the chosen queue. A message label is 1 to 64 characters long. Only letters, digits, hyphens (-), and underscores (_) are allowed. A maximum of 3 labels can be added for a message. |
delayTime |
Long |
No |
Indicates the delay time of a delay message delivery. Amount of time to delay delivery of all messages added to this queue. Value range: 0–604800000 Unit: ms If this parameter is not set or is set to 0, there is no delivery delay. If this parameter is set to a floating point number, the integer value before the decimal point is automatically used. For example, if this parameter is set to 6000.9, the value is automatically set to 6000. Only FIFO and NORMAL queues support message delivery delay. If you enable delivery delay for messages in a Kafka queue, an error message "{"code":10540010, "message":"Invalid request format: kafka queue message could not have delayTime."}" is displayed. |
Example request
{ "messages" : [{ "body" : "TEST11", "attributes" : { "attribute1" : "value1", "attribute2" : "value2" }, "tags" : ["tag1", "tag2"], "delayTime":60000 }, { "body" : { "foo" : "test02" }, "attributes" : { "attribute1" : "value1", "attribute2" : "value2" }, "tags" : ["tag1", "tag2"], "delayTime":10000 } ], "returnId" : "true" }
Response
Response parameters
Table 4 and Table 5 describe the response parameters.
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. |
id |
String |
Indicates the message ID. |
Example response
{ "messages" : [{ "error" : null, "state" : 0, "id" : "eyJ0b3BpYyI6InEtNjdjMDFiOTI5NDQxNDRhMTlkMmRhOTY4ZWYzNGE5MTItNGZhMWQ5YTQtNjRhNC00MmYxLTk3MzAtZGU4NTFjMTU0Mjg2Iiwib2Zmc2V0IjoyMzQ4LCJwYXJ0aXRpb24iOjIsInRhcmdldFRvcGljIjpudWxsfQ==", "error_code" : null }, { "error" : null, "state" : 0, "id" : "jhGwdWEpnyrXMlauz72j+7cD8W9F4I2HAk6GyQFJCJMX6Va3W7KlA2IVCZ+hYHFcKqA0n1DQLdKMCyGKvd0ZrQRfwHzjAabgYnWg2VCHtb12fJkzKMQB4JwwcyHvsPNffmFW6gxC4VVaT4cHf8sLYzrZmES1fd36r5o9wpbpqOgi2I==", "error_code" : 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.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot