File tree 2 files changed +17
-1
lines changed
2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -41,10 +41,13 @@ func main() {
41
41
log .Fatal (err )
42
42
}
43
43
44
- fmt .Println (string (body ))
45
44
if err := pusher .Push (context .Background (), string (body )); err != nil {
46
45
log .Fatal (err )
47
46
}
47
+
48
+ if err := pusher .KPush (context .Background (), "test" , string (body )); err != nil {
49
+ log .Fatal (err )
50
+ }
48
51
}
49
52
50
53
cmdline .EnterToContinue ()
Original file line number Diff line number Diff line change @@ -97,6 +97,19 @@ func (p *Pusher) Name() string {
97
97
return p .topic
98
98
}
99
99
100
+ // KPush sends a message to the Kafka topic.
101
+ func (p * Pusher ) KPush (ctx context.Context , k , v string ) error {
102
+ msg := kafka.Message {
103
+ Key : []byte (k ), // current timestamp
104
+ Value : []byte (v ),
105
+ }
106
+ if p .executor != nil {
107
+ return p .executor .Add (msg , len (v ))
108
+ } else {
109
+ return p .producer .WriteMessages (ctx , msg )
110
+ }
111
+ }
112
+
100
113
// Push sends a message to the Kafka topic.
101
114
func (p * Pusher ) Push (ctx context.Context , v string ) error {
102
115
msg := kafka.Message {
You can’t perform that action at this time.
0 commit comments