forked from premendrasingh/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
message.go
45 lines (35 loc) · 759 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
package kafka
import (
"time"
"github.com/Shopify/sarama"
"github.com/elastic/beats/libbeat/outputs"
)
type message struct {
msg sarama.ProducerMessage
topic string
key []byte
value []byte
ref *msgRef
ts time.Time
hash uint32
partition int32
data outputs.Data
}
var kafkaMessageKey interface{} = int(0)
func messageFromData(d *outputs.Data) *message {
if m, found := d.Values.Get(kafkaMessageKey); found {
return m.(*message)
}
m := &message{partition: -1}
d.AddValue(kafkaMessageKey, m)
return m
}
func (m *message) initProducerMessage() {
m.msg = sarama.ProducerMessage{
Metadata: m,
Topic: m.topic,
Key: sarama.ByteEncoder(m.key),
Value: sarama.ByteEncoder(m.value),
Timestamp: m.ts,
}
}