sarama
sarama copied to clipboard
Add producer transaction API
Inspired from https://github.com/Shopify/sarama/pull/1527 Fix:
- https://github.com/Shopify/sarama/issues/1829
- https://github.com/Shopify/sarama/issues/1760
Changes:
- Add BeginTxn/CommitTxn/AbortTxn/AddOffsetsToTxn/AddMessageToTxn to Sync/Async Producer
Example usage: (for more complete examples see examples/txn_producer && examples/exactly_once)
- Simple transaction producer
config := sarama.NewConfig()
// ...
config.Producer.Transaction.ID = "txn-unique-id"
producer, _ := sarama.NewAsyncProducer(brokers, config)
_ = producer.BeginTxn()
producer.Input() <- &sarama.ProducerMessage{Topic: "test-topic", Key: nil, Value: sarama.StringEncoder("test-value")}
_ = producer.CommitTxn() // Or producer.AbortTxn()