blob: 435a9548a5269f84b9dca57c8b3a5b2ba5691513 (
plain) (
blame)
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
|
package processor
import (
"context"
"fmt"
"log"
"github.com/segmentio/kafka-go"
)
type Processor struct {
kafka_reader *kafka.Reader
}
func NewProcessor(kafka_reader *kafka.Reader) Processor {
log.Println("Created processor")
return Processor{
kafka_reader: kafka_reader,
}
}
func (p Processor) ProcessMessages() {
for {
m, err := p.kafka_reader.ReadMessage(context.Background())
if err != nil {
break
}
fmt.Printf("message at offset %d: %s = %s\n", m.Offset, string(m.Key), string(m.Value))
}
if err := p.kafka_reader.Close(); err != nil {
log.Fatal("failed to close reader:", err)
}
}
|