如何在 NHibernate 中添加重试逻辑来处理 SQL Azure 中的瞬态故障? [英] How do I add Retry Logic in NHibernate to handle Transient Failures in SQL Azure?

查看:21
本文介绍了如何在 NHibernate 中添加重试逻辑来处理 SQL Azure 中的瞬态故障?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个 .NET 应用程序,它在 Windows Azure 上运行并使用 NHibernate 连接到 SQL Azure 数据库.有时需要添加重试逻辑来处理 SQL Azure 中的瞬时故障,例如此处所述 -

We have a .NET application that runs on Windows Azure and uses NHibernate to connect to a SQL Azure database. Sometimes it's necessary to add retry logic to handle transient failures in SQL Azure as described for example here -

http://social.technet.microsoft.com/wiki/contents/articles/retry-logic-for-transient-failures-in-sql-azure.aspx

有人能指出我用 NHibernate 做这件事的方法吗?理想情况下,我想在 NHibernate 级别执行此操作,而不是包装每个调用;正如我在此处概述的那样,我能够为另一个 ORM .netTiers (http://nettiers.com) 执行此操作 -

Can someone point me to a way in doing this with NHibernate? Ideally I'd like to do this at the NHibernate level and not wrap every single call; I was able to do this for another ORM, .netTiers (http://nettiers.com) as I outline here -

http://blog.ehuna.org/2010/01/how_to_stop_getting_exceptions.html

我确实搜索并找到了一些提到使用 IDbCommand 接口的自定义实现的答案 -

I did search and found some answers that mention using a custom implementation of the IDbCommand interface -

拦截包含 NHibernate 生成的参数值的 SQL 语句

但我不确定这是否适用于 NHibernate 3.2,我正在寻找一个可以修改的清晰示例.

But I'm not sure this works with NHibernate 3.2 and I'm looking for a clear example I could modify.

如何自动对 SQL Azure 进行 NHibernate 重试调用?假设 3 次重试,每次之间等待 100 毫秒 - 3 次重试后,如果仍然失败,我们应该抛出异常.

How could I make NHibernate retry calls to SQL Azure automatically? Let's say 3 retries, with 100ms wait between each - after the 3 retries, if still failing, we should throw the exception.

推荐答案

我发布了一个处理这个问题的库:

I've released a library that takes care of this:

https://github.com/robdmoore/NHibernate.SqlAzure

这篇关于如何在 NHibernate 中添加重试逻辑来处理 SQL Azure 中的瞬态故障?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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