简体   繁体   English

dotnet 核心中的多个 API 调用

[英]Multiple API calls in dotnet core

I am using dotnet core c#.我正在使用 dotnet core c#。 Here i need to call multiple API's based on which I have send email or SMS.在这里,我需要调用多个 API,根据这些 API 发送 email 或 SMS。 PFB the structure. PFB结构。

function SendEmailOrSMS(){
    List user = new List;
    callAPI1(userid) --> to get email id or phone number
    callAPI2(response of API 1) --> to trigger sms
    UpdateResponse() --> DB function
}

For every user I have to call this method's and API to trigger SMS or email.对于每个用户,我必须调用此方法和 API 来触发 SMS 或 email。 Now for 1000 user it takes 15 mins.现在对于 1000 个用户,需要 15 分钟。 I need to trigger for 3.5 mil users.我需要为 350 万用户触发。

If I go with 1000 user it takes almost a month to trigger email or SMS where in I need to trigger in a day.如果我的 go 有 1000 个用户,则需要将近一个月的时间才能触发 email 或 SMS,我需要在一天内触发。

Appreciate your help in advance.提前感谢您的帮助。

Does API1 or API2 expose a method for batch processing? API1 或 API2 是否公开批处理方法? If so, you won't need to call it n times, but only once (or multiple times, but still not n times).如果是这样,您将不需要调用它n次,而只需调用一次(或多次,但仍不是n次)。

Regardless, this processing can be done in parallel in different threads.无论如何,这个处理可以在不同的线程中并行完成。 This can be achieved by using the Parallel.ForEach() method, or by managing the Task s by yourself.这可以通过使用Parallel.ForEach()方法来实现,也可以通过自己管理Task来实现。 (The latter is a trickier approach, but can be more customizable.) This way, multiple users could be processed at the same time, so the processing time would decrease a lot. (后者是一种更复杂的方法,但可以更可定制。)这样可以同时处理多个用户,因此处理时间会减少很多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM