Sends a single message from an application on a cloud server to ApsaraMQ for MQTT.

Scenarios

The SendMessage operation is called by an application on a cloud server. It is complementary to the operation that is called by a ApsaraMQ for MQTT client to send messages. For more information about the differences between the scenario of sending messages from an application on a cloud server and the scenario of sending messages from a ApsaraMQ for MQTT client, see Developer guide.

Note
  • Before you call the SendMessage operation, make sure that the kernel version of your ApsaraMQ for MQTT instance is V3.3.0 or later. You can obtain the kernel version information on the Instance Details page in the ApsaraMQ for MQTT console.
  • Messages sent by calling the SendMessage operation cannot be exported to Message Queue for Apache RocketMQ. To exported messages from the ApsaraMQ for MQTT broker to Message Queue for Apache RocketMQ, use ApsaraMQ for MQTT SDK.

Limits

The SendMessage operation supports a maximum queries per second (QPS) of 1,000. For more information, see QPS limits.

Note Each successful call to the SendMessage operation is calculated as a message transaction per second (TPS). This way, you are billed for the call. For more information about the billing details, see Billing.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

ParameterTypeRequiredExampleDescription
ActionStringYesSendMessage

The operation that you want to perform. Set the value to SendMessage.

InstanceIdStringYespost-cn-0pp12gl****

The ID of the ApsaraMQ for MQTT instance. The value must be the instance ID that is used by the ApsaraMQ for MQTT client. You can view the instance ID in the Basic Information section on the Instance Details page of the instance in the ApsaraMQ for MQTT console.

MqttTopicStringYesTopicA

The topic of the ApsaraMQ for MQTT instance to which the message is sent. For more information about topics, see Terms.

PayloadStringYestest

The content of the message, which is the payload of the message. We recommend that you encode the content in Base64 to prevent non-printable characters from being transmitted.

RegionIdStringYescn-hangzhou

The region ID of the ApsaraMQ for MQTT instance.

Note For more information about other parameters, see Common parameters and Endpoints.

Response parameters

ParameterTypeExampleDescription
MsgIdString0B736D997B7F45FF54E61C1C1B58****

The unique ID of the message. After the message is sent, the ApsaraMQ for MQTT broker returns the message ID.

RequestIdString020F6A43-19E6-4B6E-B846-44EB31DF****

The ID of the request.

Examples

Sample requests

http(s)://onsmqtt.cn-hangzhou.aliyuncs.com/?Action=SendMessage
&InstanceId=post-cn-0pp12gl****
&MqttTopic=TopicA
&Payload=test
&RegionId=cn-hangzhou
&<Common request parameters>|

Sample success responses

XML format

<SendMessageResponse>
        <RequestId>020F6A43-19E6-4B6E-B846-44EB31DF****</RequestId>
        <MsgId>0B736D997B7F45FF54E61C1C1B58****</MsgId>
</SendMessageResponse>

JSON format

{
    "RequestId": "020F6A43-19E6-4B6E-B846-44EB31DF****",
    "MsgId": "0B736D997B7F45FF54E61C1C1B58****"
}

Error codes

HTTP status codeError codeError messageDescription
404ApiNotSupportThe specified API is not supported.The error message returned because the operation is not supported.
400CheckAccountInfoFailedAn error occurred while checking the account information by the STS token.The error message returned because the account information of the Security Token Service (STS) token failed to be parsed.
400InstancePermissionCheckFailedAn error occurred while validating the permissions of the instance. Please verify the account that created the instance and its permissions settings.The error message returned because the permissions on the ApsaraMQ for MQTT instance failed to be verified. Check the ownership and authorization policy of the instance.
500InternalErrorAn error occurred while processing your request. Try again later.The error message returned because the backend service of the ApsaraMQ for MQTT instance is abnormal. Try again.
400ParameterCheckFailedAn error occurred while validating the parameters. The parameters may be missing or invalid.The error message returned because the parameter failed to be verified. The parameter may be missing or invalid.
400PermissionCheckFailedAn error occurred while validating the resource permissions. Please check the account that created the instance, topic, and GroupId, and check their permission settings.The error message returned because resource permissions failed to be verified. Check the permissions and authorization policies of the instance, topic, and group ID.
500SendMessageFailedA storage exception occurred while sending the message. Please try again.The message failed to be sent because the backend storage is abnormal. Try again.
500SystemOverFlowAn error occurred while processing your request. Please try again.The error message returned because throttling is triggered. Try again.
400InvalidParameter.%sAn error occurred while validating the parameter. The parameter may be missing or invalid.The error message returned because the parameter failed to be verified. The parameter may be missing or invalid.

For a list of error codes, visit the API Error Center.