-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtopic_attribute.go
48 lines (41 loc) · 1.19 KB
/
topic_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
package alimns
import (
"encoding/xml"
"errors"
)
const (
defaultMaximumMessageSize = 65536
defaultLoggingEnabled = true
)
// TopicAttribute 修改主题属性
type TopicAttribute struct {
XMLName xml.Name `xml:"Topic"`
MaximumMessageSize int `xml:"MaximumMessageSize"`
LoggingEnabled bool `xml:"LoggingEnabled"`
}
// TopicAttributeSetter 主题属性设置函数模板
type TopicAttributeSetter func(attri *TopicAttribute) error
// DefaultTopicAttr 返回默认的主题属性
func DefaultTopicAttr() TopicAttribute {
return TopicAttribute{
MaximumMessageSize: defaultMaximumMessageSize,
LoggingEnabled: defaultLoggingEnabled,
}
}
// TopicWithMaximumMessageSize 设置消息体长度
func TopicWithMaximumMessageSize(size int) TopicAttributeSetter {
return func(attri *TopicAttribute) error {
if size < minMessageSize || size > maxMessageSize {
return errors.New("maximum message size out of range")
}
attri.MaximumMessageSize = size
return nil
}
}
// TopicWithLoggingEnabled 设置日志开启
func TopicWithLoggingEnabled(flag bool) TopicAttributeSetter {
return func(attri *TopicAttribute) error {
attri.LoggingEnabled = flag
return nil
}
}