-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
37 lines (31 loc) · 792 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
package main
import (
"fmt"
"time"
"github.com/Shopify/sarama"
)
func main() {
config := sarama.NewConfig()
config.Producer.RequiredAcks = sarama.WaitForAll
config.Producer.Partitioner = sarama.NewRandomPartitioner
config.Producer.Return.Successes = true
client, err := sarama.NewSyncProducer([]string{"192.168.126.5:9092"}, config)
if err != nil {
fmt.Println("producer close, err:", err)
return
}
defer client.Close()
msg := &sarama.ProducerMessage{}
msg.Topic = "test_log1111"
msg.Value = sarama.StringEncoder("this is a test log from aaron")
for {
pid, offset, err := client.SendMessage(msg)
if err != nil {
fmt.Println("Send message failed. err:", err)
return
}
fmt.Printf("pid:%v, offset:%v\n", pid, offset)
time.Sleep(time.Second)
}
return
}