-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathsubscription.go
104 lines (91 loc) · 2.96 KB
/
subscription.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package cmq_go
import (
"strconv"
)
type Subscription struct {
topicName string
subscriptionName string
client *CMQClient
}
func NewSubscription(topicName, subscriptionName string, client *CMQClient) *Subscription {
return &Subscription{
topicName: topicName,
subscriptionName: subscriptionName,
client: client,
}
}
func (this *Subscription) ClearFilterTags() (err error, code int) {
code = DEFAULT_ERROR_CODE
param := make(map[string]string)
param["topicName"] = this.topicName
param["subscriptionName "] = this.subscriptionName
_, err, code = doCall(this.client, param, "ClearSubscriptionFilterTags")
if err != nil {
//log.Printf("client.call ClearSubscriptionFilterTags failed: %v\n", err.Error())
return
}
return
}
func (this *Subscription) SetSubscriptionAttributes(meta SubscriptionMeta) (err error, code int) {
code = DEFAULT_ERROR_CODE
param := make(map[string]string)
param["topicName"] = this.topicName
param["subscriptionName "] = this.subscriptionName
if meta.NotifyStrategy != "" {
param["notifyStrategy"] = meta.NotifyStrategy
}
if meta.NotifyContentFormat != "" {
param["notifyContentFormat"] = meta.NotifyContentFormat
}
if meta.FilterTag != nil {
for i, flag := range meta.FilterTag {
param["filterTag."+strconv.Itoa(i+1)] = flag
}
}
if meta.BindingKey != nil {
for i, binding := range meta.BindingKey {
param["bindingKey."+strconv.Itoa(i+1)] = binding
}
}
_, err, code = doCall(this.client, param, "SetSubscriptionAttributes")
if err != nil {
//log.Printf("client.call SetSubscriptionAttributes failed: %v\n", err.Error())
return
}
return
}
func (this *Subscription) GetSubscriptionAttributes() (meta *SubscriptionMeta, err error, code int) {
code = DEFAULT_ERROR_CODE
param := make(map[string]string)
param["topicName"] = this.topicName
param["subscriptionName"] = this.subscriptionName
resMap, err, code := doCall(this.client, param, "GetSubscriptionAttributes")
if err != nil {
//log.Printf("client.call GetSubscriptionAttributes failed: %v\n", err.Error())
return
}
meta = NewSubscriptionMeta()
meta.FilterTag = make([]string, 0)
meta.BindingKey = make([]string, 0)
meta.TopicOwner = resMap["topicOwner"].(string)
meta.Endpoint = resMap["endpoint"].(string)
meta.Protocal = resMap["protocol"].(string)
meta.NotifyStrategy = resMap["notifyStrategy"].(string)
meta.NotifyContentFormat = resMap["notifyContentFormat"].(string)
meta.CreateTime = int(resMap["createTime"].(float64))
meta.LastModifyTime = int(resMap["lastModifyTime"].(float64))
meta.MsgCount = int(resMap["msgCount"].(float64))
if filterTag, found := resMap["filterTag"]; found {
for _, v := range filterTag.([]interface{}) {
filter := v.(string)
meta.FilterTag = append(meta.FilterTag, filter)
}
}
if bindingKey, found := resMap["bindingKey"]; found {
for _, v := range bindingKey.([]interface{}) {
binding := v.(string)
meta.BindingKey = append(meta.BindingKey, binding)
}
}
return
}