客户端 MQClient¶
MQ的client,用于保存aliyun账号消息,以及发送http请求
-
class
MQClient
(endpoint, accessKeyId, accessKeySecret, securityToken)¶ MQClient构造函数
new MQClient(endpoint, accessKeyId, accessKeySecret, securityToken)
- 参数
endpoint (string) – MQ的HTTP接入地址
accessKeyId (string) – 阿里云账号的AK
accessKeySecret (string) – 阿里云账号的SK
securityToken (string) – 阿里云RAM授权的STS TOKEN,可空
方法¶
-
MQClient.
buildHeaders
(method, body, resource)¶ 组装请求MQ需要的请求头
- 参数
method (string) – 请求方法
body (string) – 请求内容
resource (string) – HTTP请求URL的path
- 返回类型
object
- 返回
headers
-
MQClient.
delete
(resource, type, requestBody)¶ 发送HTTP DELETE请求
- 参数
resource (string) – HTTP请求URL的path
type (string) – 解析XML响应内容的元素名字
requestBody (string) – 请求的body
- 返回类型
object
- 返回
{ code: 200, requestId: "xxxxxxxxxxxxxx", body: {A:1,B:2,C:3} }
-
MQClient.
get
(resource, type, opts)¶ 发送HTTP GET请求
- 参数
resource (string) – HTTP请求URL的path
type (string) – 解析XML响应内容的元素名字
opts (object) – 额外请求的参数
- 返回类型
object
- 返回
{ code: 200, requestId: "xxxxxxxxxxxxxx", body: {A:1,B:2,C:3} }
-
MQClient.
getConsumer
(instanceId, topic, consumer, messageTag)¶ 构造一个MQ的消费者
- 参数
instanceId (string) – 实例ID
topic (string) – 主题名字
consumer (string) – 消费者名字
messageTag (string) – 消费的过滤标签,可空
- 返回类型
MQConsumer
- 返回
-
MQClient.
getProducer
(instanceId, topic)¶ 构造一个MQ的生产者
- 参数
instanceId (string) – 实例ID
topic (string) – 主题名字
- 返回
- 返回类型
MQProducer
-
MQClient.
getTransProducer
(instanceId, topic, groupId)¶ 构造一个MQ的事务消息生产者
- 参数
instanceId (string) – 实例ID
topic (string) – 主题名字
groupId (string) – 客户端GroupID
- 返回
- 返回类型
MQTransProducer
-
MQClient.
post
(resource, type, requestBody)¶ 发送HTTP POST请求
- 参数
resource (string) – HTTP请求URL的path
type (string) – 解析XML响应内容的元素名字
requestBody (string) – 请求的body
- 返回
{ code: 200, requestId: "xxxxxxxxxxxxxx", body: {A:1,B:2,C:3} }
- 返回类型
object
-
<async> MQClient.
request
(method, resource, type, requestBody, opts)¶ 发送http请求
- 参数
method (string) – HTTP的请求方法GET/PUT/POST/DELETE…
resource (string) – HTTP请求URL的path
type (string) – 解析XML响应内容的元素名字
requestBody (string) – 请求的body
opts (object) – 额外请求的参数
- 返回类型
object
- 返回
{ code: 200, requestId: "xxxxxxxxxxxxxx", body: {A:1,B:2,C:3} }
-
MQClient.
sign
(method, headers, resource)¶ 对请求的内容按照MQ的HTTP协议签名,sha1+base64
- 参数
method (string) – 请求方法
headers (object) – 请求头
resource (string) – HTTP请求URL的path
- 返回类型
string
- 返回
签名