C#中的Kafka交易范围
试图在MongoDB中持续一些数据,并将几条消息发布到交易中的所有内容。我正在考虑使用dotnet transactionscope,但我看不到如何将其应用于Confluent Kafka软件包。
var _database = client.GetDatabase(mongoUrl.DatabaseName);
using(var transactionScope = new TransactionScope());
{
var drinkCollections = _database.GetCollection<Drinks>("drinks").AsTransactionCollection();
var orders = _database.GetCollection<Orders>("orders").AsTransactionCollection();
_kafkaProducer.ProduceAsync("commands", "orderID", new OrderCommand() { Waiter = "John", Price = 3.35m });
transactionScope.Complete();
}
显然,如果生产方法未能发布到Kafka,则应回滚或取消对MongoDB的持久性。
不确定如何实施交易。任何想法都将不胜感激。
Trying to persist some data in MongoDB and publish a couple of messages to Kafka everything inside of a transaction. I was thinking of using the dotnet TransactionScope but I do not see how to apply it to the Confluent Kafka packages.
var _database = client.GetDatabase(mongoUrl.DatabaseName);
using(var transactionScope = new TransactionScope());
{
var drinkCollections = _database.GetCollection<Drinks>("drinks").AsTransactionCollection();
var orders = _database.GetCollection<Orders>("orders").AsTransactionCollection();
_kafkaProducer.ProduceAsync("commands", "orderID", new OrderCommand() { Waiter = "John", Price = 3.35m });
transactionScope.Complete();
}
Obviously if the ProduceAsync method fails to publish to Kafka then it should rollback or cancel the persistence to MongoDb.
Not sure how to implement the transaction. Any ideas would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论