-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
56 lines (45 loc) · 1.3 KB
/
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
package main
import (
"flag"
"github.com/go-redis/redis"
"log"
"copper-face-jacks/consumer"
)
var (
brokers = ""
version = ""
group = ""
topics = ""
oldest = true
)
func parseFlags() {
flag.StringVar(&brokers, "brokers", "localhost:9092", "Kafka bootstrap brokers to connect to")
flag.StringVar(&version, "version", "2.1.1", "kafka cluster version")
flag.StringVar(&group, "group", "test-consumer-group", "kafka consumer group definition")
flag.StringVar(&topics, "topics", "test_topic", "kafka topics to be consumed")
flag.BoolVar(&oldest, "oldest", true, "kafka consumer consume initial offset from oldest")
flag.Parse()
if len(brokers) == 0 {
panic("Sorry, no Kafka bootstrap brokers defined. Try to set the -brokers flag")
}
if len(topics) == 0 {
panic("Sorry, no topics given to be consumed. Try to set the -topics flag")
}
if len(group) == 0 {
panic("Sorry, no Kafka consumer group defined. Try to set the -group flag")
}
}
func main() {
parseFlags()
// make connection to redis image instance
client := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "",
DB: 0,
})
_, err := client.Ping().Result()
if err != nil {
log.Panic("Oops, sorry: Unable to ping redis", err)
}
consumer.Setup(brokers, version, group, topics, oldest, client)
}