-
Notifications
You must be signed in to change notification settings - Fork 93
/
message.go
61 lines (49 loc) · 1.35 KB
/
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
51
52
53
54
55
56
57
58
59
60
61
package rocketmqClientGo
import (
"github.com/apache/rocketmq-client-go/v2/primitive"
"go.opentelemetry.io/otel/propagation"
)
var _ propagation.TextMapCarrier = (*ProducerMessageCarrier)(nil)
var _ propagation.TextMapCarrier = (*ConsumerMessageCarrier)(nil)
type ProducerMessageCarrier struct {
msg *primitive.Message
}
func NewProducerMessageCarrier(msg *primitive.Message) ProducerMessageCarrier {
return ProducerMessageCarrier{msg: msg}
}
func (c ProducerMessageCarrier) Get(key string) string {
return c.msg.GetProperty(key)
}
func (c ProducerMessageCarrier) Set(key, val string) {
c.msg.WithProperty(key, val)
}
func (c ProducerMessageCarrier) Keys() []string {
out := make([]string, len(c.msg.GetProperties()))
var i = 0
for k := range c.msg.GetProperties() {
out[i] = k
i++
}
return out
}
type ConsumerMessageCarrier struct {
msg *primitive.MessageExt
}
func NewConsumerMessageCarrier(msg *primitive.MessageExt) ConsumerMessageCarrier {
return ConsumerMessageCarrier{msg: msg}
}
func (c ConsumerMessageCarrier) Get(key string) string {
return c.msg.GetProperty(key)
}
func (c ConsumerMessageCarrier) Set(key, val string) {
c.msg.WithProperty(key, val)
}
func (c ConsumerMessageCarrier) Keys() []string {
out := make([]string, len(c.msg.GetProperties()))
var i = 0
for k := range c.msg.GetProperties() {
out[i] = k
i++
}
return out
}