NServiceBus - 在消息处理程序中使用 TransactionScopeOption.Suppress 的问题 [英] NServiceBus - Problem with using TransactionScopeOption.Suppress in message handler

查看:38
本文介绍了NServiceBus - 在消息处理程序中使用 TransactionScopeOption.Suppress 的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个端点,它有一个执行一些 FTP 工作的消息处理程序.由于 ftp 过程需要一些时间,我将 ftp 方法封装在一个 TransactionScope 中,并使用 TransactionScopeOption.Suppress 来防止事务超时异常.

I have an endpoint that has a message handler which does some FTP work. Since the ftp process can take some time, I encapsulated the ftp method within a TransactionScope with TransactionScopeOption.Suppress to prevent the transaction timeout exceptions.

这样做消除了超时异常,但是处理程序被触发了 5 次(重试在我的配置文件中设置为 5)

Doing this got rid of the timeout exceptions, however the handler was fired 5 times (retries is set to 5 in my config file)

文件 ftp 没问题,但它们只是 ftp 5 次.

The files were ftp'd ok, but they were just ftp'd 5 times.

处理程序看起来像是在 10 或 11 分钟后重新启动.

the handler look like it is re-fired after 10 or 11 minutes.

一些测试代码如下:

public void Handle(FtpMessage msg)
{
     using (TransactionScope t = new TransactionScope(TransactionScopeOption.Suppress))
     {
          FtpFile(msg);
     }
}

任何帮助将不胜感激.

谢谢.

推荐答案

我的猜测是,如果没有完成内部作用域,就会导致由 NSB 创建的外部作用域回滚.这将导致 NSB 重试您的 FtpMessage.

My guess is that by not completing the inner scope you're causing the outer scope, created by NSB, to rollback. This will cause NSB to retry your FtpMessage.

尝试添加:t.Complete();在您调用 FtpFile 之后,看看它是否适合您.

Try to add: t.Complete(); after your call to FtpFile and see if that does it for you.

重读您的问题后,我意识到这不会解决您的超时问题.您是否尝试过增加超时时间?(10 分钟是machine.config 中的默认maxValue,因此您不能在不修改machine.config 的情况下将其设置为更高)

After rereading your question I realized that this won't solve your timeout issue. Have you tried to increase the timeout? (10 min is the default maxValue in machine.config so you can't set it to higher without modifying machine.config)

这篇关于NServiceBus - 在消息处理程序中使用 TransactionScopeOption.Suppress 的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆