You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kratos/examples/event/sender/main.go

31 lines
571 B

package main
import (
"context"
"fmt"
"github.com/go-kratos/kratos/examples/event/event"
"github.com/go-kratos/kratos/examples/event/kafka"
)
func main() {
sender, err := kafka.NewKafkaSender([]string{"localhost:9092"}, "kratos")
if err != nil {
panic(err)
}
for i := 0; i < 50; i++ {
send(sender)
}
_ = sender.Close()
}
func send(sender event.Sender) {
msg := kafka.NewMessage("kratos", []byte("hello world"))
err := sender.Send(context.Background(), msg)
if err != nil {
panic(err)
}
fmt.Printf("key:%s, value:%s\n", msg.Key(), msg.Value())
}