package main import ( . "antoine-roux.tk/kafka/internal/configuration" "github.com/Shopify/sarama" "log" _ "net/http/pprof" "os" ) func main() { configuration := NewConfiguration() if configuration.IsVerbose() { sarama.Logger = log.New(os.Stdout, "[sarama] ", log.LstdFlags) } application := configuration.CreateApplication() // producer code provider := application.ProducerProvider producer := provider.Borrow() defer provider.Release(producer) err := producer.BeginTxn() if err != nil { log.Printf("unable to start txn %s\n", err) return } for i := 0; i < 10; i++ { _, _, err := producer.SendMessage(&sarama.ProducerMessage{ Topic: string(application.EmitterTopic), Key: nil, Value: sarama.StringEncoder("test"), }) if err != nil { log.Printf("Message delivery error %s\n", err) } } err = producer.CommitTxn() if err != nil { log.Printf("unable to commit txn %s\n", err) return } }