-
Notifications
You must be signed in to change notification settings - Fork 0
/
message.go
50 lines (41 loc) · 836 Bytes
/
message.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
package redis
import (
"sync/atomic"
)
type Message struct {
*XMessage
ConsumerGroup string
Stream string
Delegate MessageDelegate
responded int32
killed int32
}
func (m *Message) Ack() {
if !atomic.CompareAndSwapInt32(&m.responded, 0, 1) {
return
}
m.Delegate.OnAck(m)
}
func (m *Message) Del() {
if !atomic.CompareAndSwapInt32(&m.killed, 0, 1) {
return
}
m.Delegate.OnDel(m)
}
func (m *Message) HasResponded() bool {
return atomic.LoadInt32(&m.responded) == 1 ||
atomic.LoadInt32(&m.killed) == 1
}
func (m *Message) Content(opts ...DecodeMessageContentOption) *MessageContent {
content := DecodeMessageContent(m.Values, opts...)
if content != nil {
return content
}
return &MessageContent{
Values: m.Values,
}
}
func (m *Message) Clone() *Message {
cloned := *m
return &cloned
}