forked from lovoo/goka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
event.go
78 lines (63 loc) · 1.6 KB
/
event.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
package kafka
import (
"fmt"
"time"
)
// Event abstracts different types of events from the kafka consumer like BOF/EOF/Error or an actual message
type Event interface {
string() string
}
// Assignment represents a partition:offset assignment for the current connection
type Assignment map[int32]int64
func (a *Assignment) string() string {
var am map[int32]int64 = *a
return fmt.Sprintf("Assignment %v", am)
}
// EOF marks the end of the log of a topic/partition.
type EOF struct {
Topic string
Partition int32
Hwm int64
}
func (e *EOF) string() string {
return fmt.Sprintf("EOF %s/%d:%d", e.Topic, e.Partition, e.Hwm)
}
// BOF marks the beginning of a topic/partition.
type BOF struct {
Topic string
Partition int32
Offset int64
Hwm int64
}
func (e *BOF) string() string {
return fmt.Sprintf("BOF %s/%d:%d->%d", e.Topic, e.Partition, e.Offset, e.Hwm)
}
// Message represents a message from kafka containing
// extra information like topic, partition and offset for convenience
type Message struct {
Topic string
Partition int32
Offset int64
Timestamp time.Time
Header map[string][]byte
Key string
Value []byte
}
func (m *Message) string() string {
return fmt.Sprintf("Message %s/%d:%d %s=%v", m.Topic, m.Partition, m.Offset, m.Key, m.Value)
}
// Error from kafka wrapped to be conform with the Event-Interface
type Error struct {
Err error
}
func (e *Error) string() string {
return e.Err.Error()
}
// NOP does not carry any information. Useful for debugging.
type NOP struct {
Topic string
Partition int32
}
func (n *NOP) string() string {
return "nop"
}