sarama icon indicating copy to clipboard operation
sarama copied to clipboard

Add producer transaction API

Open ryarnyah opened this issue 3 years ago • 0 comments

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()

ryarnyah avatar Jul 27 '22 13:07 ryarnyah