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 method
string 请求方法
body
string 请求内容
resource
string HTTP请求URL的path
Returns:
headers
- Type
- object
-
delete(resource, type, requestBody)
-
发送HTTP DELETE请求
Parameters:
Name Type Description resource
string HTTP请求URL的path
type
string 解析XML响应内容的元素名字
requestBody
string 请求的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 resource
string HTTP请求URL的path
type
string 解析XML响应内容的元素名字
opts
object 额外请求的参数
Returns:
{ code: 200, requestId: "xxxxxxxxxxxxxx", body: {A:1,B:2,C:3} }
- Type
- object
-
getConsumer(instanceId, topic, consumer, messageTag)
-
构造一个MQ的消费者
Parameters:
Name Type Description instanceId
string 实例ID
topic
string 主题名字
consumer
string 消费者名字
messageTag
string 消费的过滤标签,可空
Returns:
- Type
- MQConsumer
-
getProducer(instanceId, topic)
-
构造一个MQ的生产者
Parameters:
Name Type Description instanceId
string 实例ID
topic
string 主题名字
Returns:
- Type
- MQProducer
-
getTransProducer(instanceId, topic, groupId)
-
构造一个MQ的事务消息生产者
Parameters:
Name Type Description instanceId
string 实例ID
topic
string 主题名字
groupId
string 客户端GroupID
Returns:
- Type
- MQTransProducer
-
post(resource, type, requestBody)
-
发送HTTP POST请求
Parameters:
Name Type Description resource
string HTTP请求URL的path
type
string 解析XML响应内容的元素名字
requestBody
string 请求的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 method
string HTTP的请求方法GET/PUT/POST/DELETE...
resource
string HTTP请求URL的path
type
string 解析XML响应内容的元素名字
requestBody
string 请求的body
opts
object 额外请求的参数
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 method
string 请求方法
headers
object 请求头
resource
string HTTP请求URL的path
Returns:
签名
- Type
- string