new MQClient(endpoint, accessKeyId, accessKeySecret, securityToken)
MQClient构造函数
Parameters:
| Name | Type | Description |
|---|---|---|
endpoint |
string | MQ的HTTP接入地址 |
accessKeyId |
string | 阿里云账号的AK |
accessKeySecret |
string | 阿里云账号的SK |
securityToken |
string | 阿里云RAM授权的STS TOKEN,可空 |
Returns:
- Type
- MQClient
Methods
-
buildHeaders(method, body, resource)
-
组装请求MQ需要的请求头
Parameters:
Name Type Description methodstring 请求方法
bodystring 请求内容
resourcestring HTTP请求URL的path
Returns:
headers
- Type
- object
-
delete(resource, type, requestBody)
-
发送HTTP DELETE请求
Parameters:
Name Type Description resourcestring HTTP请求URL的path
typestring 解析XML响应内容的元素名字
requestBodystring 请求的body
Returns:
{ code: 200, requestId: "xxxxxxxxxxxxxx", body: {A:1,B:2,C:3} }- Type
- object
-
get(resource, type, opts)
-
发送HTTP GET请求
Parameters:
Name Type Description resourcestring HTTP请求URL的path
typestring 解析XML响应内容的元素名字
optsobject 额外请求的参数
Returns:
{ code: 200, requestId: "xxxxxxxxxxxxxx", body: {A:1,B:2,C:3} }- Type
- object
-
getConsumer(instanceId, topic, consumer, messageTag)
-
构造一个MQ的消费者
Parameters:
Name Type Description instanceIdstring 实例ID
topicstring 主题名字
consumerstring 消费者名字
messageTagstring 消费的过滤标签,可空
Returns:
- Type
- MQConsumer
-
getProducer(instanceId, topic)
-
构造一个MQ的生产者
Parameters:
Name Type Description instanceIdstring 实例ID
topicstring 主题名字
Returns:
- Type
- MQProducer
-
getTransProducer(instanceId, topic, groupId)
-
构造一个MQ的事务消息生产者
Parameters:
Name Type Description instanceIdstring 实例ID
topicstring 主题名字
groupIdstring 客户端GroupID
Returns:
- Type
- MQTransProducer
-
post(resource, type, requestBody)
-
发送HTTP POST请求
Parameters:
Name Type Description resourcestring HTTP请求URL的path
typestring 解析XML响应内容的元素名字
requestBodystring 请求的body
Returns:
{ code: 200, requestId: "xxxxxxxxxxxxxx", body: {A:1,B:2,C:3} }- Type
- object
-
<async> request(method, resource, type, requestBody, opts)
-
发送http请求
Parameters:
Name Type Description methodstring HTTP的请求方法GET/PUT/POST/DELETE...
resourcestring HTTP请求URL的path
typestring 解析XML响应内容的元素名字
requestBodystring 请求的body
optsobject 额外请求的参数
Returns:
{ code: 200, requestId: "xxxxxxxxxxxxxx", body: {A:1,B:2,C:3} } ```json- Type
- object
-
sign(method, headers, resource)
-
对请求的内容按照MQ的HTTP协议签名,sha1+base64
Parameters:
Name Type Description methodstring 请求方法
headersobject 请求头
resourcestring HTTP请求URL的path
Returns:
签名
- Type
- string