-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
58 lines (46 loc) · 968 Bytes
/
main.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
package main
import (
"bufio"
"fmt"
"io"
"os"
"github.com/Shopify/sarama"
)
func main() {
logPath := os.Args[1]
logFile, err := os.Open(logPath)
if err != nil {
panic(err)
}
defer logFile.Close()
r := bufio.NewReader(logFile)
config := sarama.NewConfig()
config.Producer.RequiredAcks = sarama.WaitForAll
config.Producer.Retry.Max = 5
config.Producer.Return.Successes = true
config.Producer.MaxMessageBytes = 10000000
//brokers := []string{"54.233.238.100:9092"}
brokers := []string{"172.31.42.185:9092"}
producer, err := sarama.NewSyncProducer(brokers, config)
if err != nil {
panic(err)
}
defer producer.Close()
for {
line, err := r.ReadBytes('\n')
if err == io.EOF {
break
}
msg := &sarama.ProducerMessage{
Topic: "logs",
Value: sarama.StringEncoder(line),
}
_, _, err = producer.SendMessage(msg)
if err != nil {
panic(err)
}
if err != nil {
fmt.Println("Error sending to kafka", err)
}
}
}