-
Notifications
You must be signed in to change notification settings - Fork 173
/
topicinit.go
35 lines (31 loc) · 952 Bytes
/
topicinit.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
package topicinit
import (
"github.com/lovoo/goka"
"log"
)
// EnsureStreamExists is a convenience wrapper for TopicManager.EnsureStreamExists
func EnsureStreamExists(topic string, brokers []string) {
tm := createTopicManager(brokers)
defer tm.Close()
err := tm.EnsureStreamExists(topic, 8)
if err != nil {
log.Printf("Error creating kafka topic %s: %v", topic, err)
}
}
// EnsureTableExists is a convenience wrapper for TopicManager.EnsureTableExists
func EnsureTableExists(topic string, brokers []string) {
tm := createTopicManager(brokers)
defer tm.Close()
err := tm.EnsureTableExists(topic, 8)
if err != nil {
log.Printf("Error creating kafka topic %s: %v", topic, err)
}
}
func createTopicManager(brokers []string) goka.TopicManager {
tmc := goka.NewTopicManagerConfig()
tm, err := goka.NewTopicManager(brokers, goka.DefaultConfig(), tmc)
if err != nil {
log.Fatalf("Error creating topic manager: %v", err)
}
return tm
}