forked from bittelc/testing-kafka-events
-
Notifications
You must be signed in to change notification settings - Fork 0
/
producer.go
41 lines (37 loc) · 816 Bytes
/
producer.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
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
// mainProducer() creates a Kafka producer with the
// archetypal config defined in kafka.go
func mainProducer() {
var err error
reader := bufio.NewReader(os.Stdin)
kafka := newKafkaSyncProducer()
for {
fmt.Print("->")
text, _ := reader.ReadString('\n')
text = strings.Replace(text, "\n", "", -1)
args := strings.Split(text, "###")
cmd := args[0]
switch cmd {
case "create":
if len(args) == 2 {
accName := args[1]
event := NewCreateAccountEvent(accName)
sendMsg(kafka, event)
} else {
fmt.Println("Only specify create###Account Name")
}
default:
fmt.Printf("Unknown command $s, only: create, deposit, withdraw, transfer\n", cmd)
}
if err != nil {
fmt.Printf("Error: %s\n", err)
err = nil
}
}
}