-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathget_queue_attribute.go
55 lines (48 loc) · 1.62 KB
/
get_queue_attribute.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
package alimns
import (
"context"
"encoding/xml"
"errors"
"fmt"
"net/http"
)
// QueueAttributeResponse 消息队列属性回复
type QueueAttributeResponse struct {
XMLName xml.Name `xml:"Queue"`
QueueName string `xml:"QueueName"`
CreateTime string `xml:"CreateTime"`
LastModifyTime string `xml:"LastModifyTime"`
DelaySeconds int `xml:"DelaySeconds"`
MaximumMessageSize int `xml:"MaximumMessageSize"`
MessageRetentionPeriod int `xml:"MessageRetentionPeriod"`
VisibilityTimeout int `xml:"VisibilityTimeout"`
PollingWaitSeconds int `xml:"PollingWaitSeconds"`
Activemessages string `xml:"Activemessages"`
InactiveMessages string `xml:"InactiveMessages"`
DelayMessages string `xml:"DelayMessages"`
LoggingEnabled bool `xml:"LoggingEnabled"`
}
// GetQueueAttributes 获取消息队列属性
func (c *Client) GetQueueAttributes(name string) (*QueueAttributeResponse, error) {
var err error
requestLine := fmt.Sprintf(mnsGetQueueAttributes, name)
req := c.ca.NewRequest().Get().WithPath(requestLine).WithTimeout(apiTimeout)
resp, err := c.ca.Do(context.TODO(), req)
if err != nil {
return nil, err
}
switch resp.StatusCode() {
case http.StatusOK:
var queueAttributeResponse QueueAttributeResponse
if err := resp.DecodeFromXML(&queueAttributeResponse); err != nil {
return nil, err
}
return &queueAttributeResponse, nil
default:
var respErr RespErr
if err := resp.DecodeFromXML(&respErr); err != nil {
return nil, err
}
return nil, errors.New(respErr.Code)
}
}