调用SendMessage接口从服务端应用向云消息队列 MQTT 版发送单条消息。
使用场景
SendMessage接口为服务端应用调用,与MQTT客户端发送消息互补。服务端和客户端的使用场景区别,请参见开发指南使用指引。
使用限制
SendMessage接口的QPS限制为1000。更多信息,请参见QPS限制。
说明 每成功调用一次SendMessage接口,都会计算为一次消息TPS,从而影响您的计费。计费详情,请参见计费说明。
调试
您可以在OpenAPI Explorer中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI Explorer可以自动生成SDK代码示例。
请求参数
名称 | 类型 | 是否必选 | 示例值 | 描述 |
---|---|---|---|---|
Action | String | 是 | SendMessage | 系统规定参数。取值:SendMessage。 |
MqttTopic | String | 是 | TopicA | 将消息发往的云消息队列 MQTT 版的Topic。Topic的详细说明请参见名词解释。 |
InstanceId | String | 是 | post-cn-0pp12gl**** | 云消息队列 MQTT 版实例的ID,一定要和客户端实际使用的实例ID匹配。您可以在控制台实例详情页面的基础信息区域查看。 |
Payload | String | 是 | test | 消息内容,即消息负载。建议自行做Base64编码,避免传输不可见字符。 |
返回数据
名称 | 类型 | 示例值 | 描述 |
---|---|---|---|
MsgId | String | 0B736D997B7F45FF54E61C1C1B58**** | 消息的唯一标识,消息发送成功后服务端会返回消息ID。 |
RequestId | String | 020F6A43-19E6-4B6E-B846-44EB31DF**** | 公共参数,每个请求的ID都是唯一的。 |
示例
请求示例
http(s)://onsmqtt.cn-hangzhou.aliyuncs.com/?Action=SendMessage
&InstanceId=post-cn-0pp12gl****
&MqttTopic=TopicA
&Payload=test
&RegionId=cn-hangzhou
&<公共请求参数>
正常返回示例
XML
格式
HTTP/1.1 200 OK
Content-Type:application/xml
<SendMessageResponse>
<RequestId>020F6A43-19E6-4B6E-B846-44EB31DF****</RequestId>
<MsgId>0B736D997B7F45FF54E61C1C1B58****</MsgId>
</SendMessageResponse>
JSON
格式
HTTP/1.1 200 OK
Content-Type:application/json
{
"RequestId" : "020F6A43-19E6-4B6E-B846-44EB31DF****",
"MsgId" : "0B736D997B7F45FF54E61C1C1B58****"
}
错误码
HttpCode | 错误码 | 错误信息 | 描述 |
---|---|---|---|
400 | CheckAccountInfoFailed | An error occurred while checking the account information by the STS token. | 解析 STS Token 账号信息失败。 |
400 | InstancePermissionCheckFailed | An error occurred while validating the permissions of the instance. Please verify the account that created the instance and its permissions settings. | 实例权限校验失败,请确认 MQTT 实例的所属关系以及授权策略。 |
400 | ParameterCheckFailed | An error occurred while validating the parameters. The parameters may be missing or invalid. | 参数校验失败,可能缺失或者传入值非法。 |
400 | PermissionCheckFailed | An error occurred while validating the resource permissions. Please check the account that created the instance, topic, and GroupId, and check their permission settings. | 资源权限校验失败,请检查实例、Topic 和 Group ID 的所属权限和授权策略。 |
400 | InvalidParameter.%s | An error occurred while validating the parameter. The parameter may be missing or invalid. | 参数校验失败,可能缺失或者传入值非法。 |
500 | InternalError | An error occurred while processing your request. Try again later. | MQTT 后端服务异常,请重试。 |
500 | SendMessageFailed | A storage exception occurred while sending the message. Please try again. | 由于后端存储异常,消息发送失败,请重试。 |
500 | SystemOverFlow | An error occurred while processing your request. Please try again. | 系统限流,请重试。 |
404 | ApiNotSupport | The specified API is not supported. | 当前接口不支持,请检查。 |
访问错误中心查看更多错误码。