【发布时间】:2019-03-06 01:31:23
【问题描述】:
情况:我有一堆天蓝色的功能,可以从各种网站获取数据。网站的域发生变化,每个函数都会进行多次 http 调用。当网站 A 的功能不从网站 B 提取数据时,这一点非常重要。
我在读到最好重用您的 httpclient/restclient 等。
链接:HttpClient best practices in Azure Functions
但我想要关于如何正确执行此操作的建议。
public class WebsiteCaller
{
private static RestClient httpClient = new RestSharp.RestClient();
public WebsiteCaller(string domainName)
{
httpClient = new RestClient(domainName);
}
public object GetWebData1(string parameters)
{
//use httpClient with parameters and return data
}
public object GetWebData2(string parameters)
{
//use httpClient with parameters and return data
}
}
public class Manager
{
public void GetDataAndDoStuff()
{
var webConnection = new WebsiteCaller("clientnameDomain.com");
var result1 = webConnection.GetWebData1("name=something");
//Do something with result1
var result2 = webConnection.GetWebData2("name=result1Info");
//Continue making more http calls
}
}
如果此函数是从队列触发器中触发的,那么一分钟可能会发生数百次。我是否必须使用 Job2 中的 RestClient 担心队列中的 Job1。有没有更好的方法来处理这个问题?
我将直接 HttpClient 用于我的应用程序的某些部分,将 RestClient 用于其他部分(新的和旧的)。这就是为什么我在这个问题中提到两者。
这仍在 Azure Functions 1.x .net 标准中
【问题讨论】:
标签: azure azure-functions restsharp dotnet-httpclient