如何解决如何使用C#实现重试模式?
我有一个代理服务器的列表。使用这些代理服务器,我想点击URL以编程方式获取数据。我想在此处应用重试模式。例如,如果我无法从代理服务器1获取数据,我想使用代理服务器2来访问URL,依此类推。根据良好的设计规范,我应该在 ProxyHelper类GetData方法中写什么。
示例代码:
Interface IProxyServer {
IResponse GetData(String URL);
}
public class ProxyServerA implements IProxyServer {
public IResponse GetData(String URL)
{
//some code
}
}
public class ProxyServerB implements IProxyServer {
public IResponse GetData(String URL) {
//some code
}
}
public class ProxyHelper {
public List<IProxyServer> _proxyservers = new List<IProxyServer>();
public IResponse GetData(String URL)
{
// Following the best practices,what should be the code here which will implement retry mechanism
// and call other available proxy server in case the request is failed.
}
public void Add(IProxyServer proxyserver)
{
_proxyservers.Add(proxyserver);
}
}
void main() {
ProxyHelper proxyHelper = new ProxyHelper();
String URL = "www.google.com";
proxyserver.Add(new ProxyServerA());
proxyserver.Add(new ProxyServerB());
var response = ProxyHelper.GetData(URL);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。