消息队列的 TransactionScope 问题

发布于 2024-08-22 07:20:59 字数 545 浏览 8 评论 0原文

我面临下一个问题。我有一段代码,如下所示:

DoSomething(){
  using (TransactionScope scope = new TransactionScope())
    {
      InsertSomething();
      InsertSomethingElse();
      InsertYetAnotherThing();
      ProcessDataRelatedWithThePreviousInserts();
      scope.Complete()
    }
}

在 ProcessDataRelatedWithThePreviousInserts 中,我检查条件,如果需要,其余的工作流程将重定向到其他服务器中的消息队列。在另一台服务器中,我恢复消息,并继续工作流程(基本上,进行一些与 DoSomething 方法上的插入相关的其他插入)。

这是理论上的,因为只有在 DoSomething 方法中删除 TransactionScope 时,我才能做到这一点。有没有办法完成我想做的事情,或者我需要改变交易的处理方式?

I'm facing the next problem. I have a piece of code that goes like this:

DoSomething(){
  using (TransactionScope scope = new TransactionScope())
    {
      InsertSomething();
      InsertSomethingElse();
      InsertYetAnotherThing();
      ProcessDataRelatedWithThePreviousInserts();
      scope.Complete()
    }
}

In ProcessDataRelatedWithThePreviousInserts I check for a condition and if needed, the rest of the work flow is redirected to a Message Queue in other server. In the other server, I recover the message, and continue the workflow (basically, make some other insertions that are related with the ones on the DoSomething method).

This is in theory, because I only manage to do that if I remove the TransactionScope in the DoSomething method. Is there a way to accomplish what I want to do or I'll need to change the way the transactions are handled?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

攒一口袋星星 2024-08-29 07:20:59

您是否已尝试

using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))
{
    // ...
    using (TransactionScope innerscope = new TransactionScope(TransactionScopeOption.Supress)
    {
        ProcessDataRelatedWithThePreviousInserts();
    }
    scope.Complete();
}

显式抑制调用 ProcessDataRelatedWithThePreviousInserts() 的外部事务。

Did you already try

using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))
{
    // ...
    using (TransactionScope innerscope = new TransactionScope(TransactionScopeOption.Supress)
    {
        ProcessDataRelatedWithThePreviousInserts();
    }
    scope.Complete();
}

explicitly supressing the outer transaction for your call to ProcessDataRelatedWithThePreviousInserts().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文