-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue_create.go
64 lines (60 loc) · 1.59 KB
/
queue_create.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package go_cmq
import (
"encoding/json"
"errors"
"strconv"
)
type QueueCreateReq struct {
QueueName string
MaxMsgHeapNum int
PollingWaitSeconds int
VisibilityTimeout int
MaxMsgSize int
MsgRetentionSeconds int
RewindSeconds int // 回溯时间设置应该小于43200,并且不能大于消息生命周期
}
type QueueCreateResp struct {
BaseResponse
QueueID string `json:"queueId"`
}
func (a *Account) CreateQueue(req QueueCreateReq) (*QueueCreateResp, error) {
params := getCommonParams(reqCommon{
Action: "CreateQueue",
SecretId: a.SecretID,
SignatureMethod: a.SignatureMethod,
Region: a.Region,
Token: a.Token,
})
if req.QueueName == "" {
return nil, errors.New("queueName is required")
}
params["queueName"] = req.QueueName
if req.MaxMsgHeapNum > 0 {
params["maxMsgHeapNum"] = strconv.Itoa(req.MaxMsgHeapNum)
}
if req.PollingWaitSeconds > 0 {
params["pollingWaitSeconds"] = strconv.Itoa(req.PollingWaitSeconds)
}
if req.VisibilityTimeout > 0 {
params["visibilityTimeout"] = strconv.Itoa(req.VisibilityTimeout)
}
if req.MaxMsgSize > 0 {
params["maxMsgSize"] = strconv.Itoa(req.MaxMsgSize)
}
if req.MsgRetentionSeconds > 0 {
params["msgRetentionSeconds"] = strconv.Itoa(req.MsgRetentionSeconds)
}
if req.RewindSeconds > 0 {
params["rewindSeconds"] = strconv.Itoa(req.RewindSeconds)
}
a.domain = a.QueueDomain
resp, e := a.getResponse(params)
if e != nil {
return nil, e
}
var res QueueCreateResp
if err := json.Unmarshal(resp, &res); err != nil {
return nil, err
}
return &res, nil
}