azure多功能成像好用嗎_Azure持久功能簡介:模式和最佳實踐

azure多功能成像好用嗎

Authored with Steef-Jan Wiggers at Microsoft Azure

由Microsoft Azure的Steef-Jan Wiggers撰寫

With Durable Functions, you can program a workflow and instantiate tasks in sequential or parallel order, or you can build a watch or support a human interaction flow (approval workflow). You can chain functions to control your flow. You can use fan-in and fan-out scenarios, correlating events, flexible automation, and long-running processes, and human interaction patterns that are hard to put in place with only functions or with logic apps.

使用“耐用功能”,您可以對工作流程進行編程并按順序或并行順序實例化任務,或者可以構建手表或支持人機交互流程( 批準工作流程 )。 您可以鏈接函數來控制流程。 您可以使用扇入和扇出場景,關聯事件,靈活的自動化和長期運行的流程,以及僅通過功能或邏輯應用程序難以實現的人機交互模式。

鏈接功能 (Chaining functions)

The most natural and straightforward use of Durable Functions is chaining functions together. You have one orchestrator function that calls many functions in the order you desire. You can do this with functions alone and using Service Bus Queues, yet you will face some challenges:

持久功能最自然,最直接的用法是將功能鏈接在一起。 您擁有一個編排器函數,該函數以所需的順序調用許多函數。 您可以單獨使用功能并使用服務總線隊列來完成此操作,但是您將面臨一些挑戰:

  • no visualization to show the relationship between functions and queues

    沒有可視化顯示功能和隊列之間的關系
  • middle queues are an implementation detail, with a conceptual overhead

    中間隊列是一個實現細節,具有概念上的開銷
  • error handling adds a lot more complexity

    錯誤處理增加了更多的復雜性

Using Durable Functions, you will not run into those challenges. With an orchestrator you:

使用持久功能,您將不會遇到這些挑戰。 與協調器一起您可以:

  • can have a central place to set the order of function calls (relations)

    可以在中心位置設置函數調用(關系)的順序
  • need no management of queues — under the hood, Durable Functions use and manage storage queues

    無需管理隊列-持久功能在后臺使用和管理存儲隊列
  • have central error handling — when an error occurs in one of the activity functions, the error propagates back to the orchestrator

    具有集中的錯誤處理功能—當活動功能之一發生錯誤時,該錯誤會傳播回協調器
//calls functions in sequence
public static async Task<object> Run (DurableOrchestrationContext ctx)
{ try{var x = await ctx.CallFunctionAsync (“F1”);var y = await ctx.callFunctionAsync (“F2”, x);var z = await ctx.callFunctionAsync (“F3”, y);return = await ctx.CallFunctionAsync (“F4”, z);}catch (Exception ){//global error handling /compensation goes here}
}

扇出/扇入 (Fan-out/Fan-in)

Fan-out/fan-in can be used when you need to execute one or more functions in parallel and, based on the results, you run some other tasks. With functions, you cannot put in place such an approach. Moreover, you will also face the challenges mentioned in the previous section. But, with Durable Functions, you can achieve fan-out/fan-in:

當您需要并行執行一個或多個功能,并根據結果運行一些其他任務時,可以使用扇出/扇入。 使用函數,您將無法采用這種方法。 此外,您還將面臨上一節中提到的挑戰。 但是,通過耐用功能,您可以實現扇出/扇入:

public static async Task Run (Durableorchestrationcontext ctx)
{
var parallelTasks = new List<Task<int>>();
//get a list of N work items to process in parallel
object []workBatch = await ctx.CallFunctionAsync<object[]> (“F1”);
for (int i = 0; i < workBatch.Length; i++)
{
Task<int> task = ctx.CallFunctionAsync <int> (“F2”, workBatch [i]); 
parallelTasks.Add (task);
}
await Task.WhenAll(parallelTasks);
//aggregate all N outputs and send result to F3
int sum = parallelTasks.Sum(t=> t.Result); 
await ctx.CallFunctionAsync (“F3”, sum);
}

HTTP異步響應 (HTTP Async Response)

With functions, it is possible that when you call another API you do not know the amount of time it would take before a response is returned. For example, latency and volume can cause the time it would make the API to process the request and return a response to be unknown.

使用函數,當您調用另一個API時,您可能不知道返回響應之前所花費的時間。 例如,延遲和數量會導致使API處理請求并返回響應的時間變得未知。

A function can time-out when using a Consumption plan. The state needs to be maintained, which is undesirable for functions, as they need to be stateless. Durable Functions provide built-in APIs that simplify the code you write for interacting with long-running function executions. Furthermore, the state is managed by the Durable Functions run-time.

使用消耗計劃時,功能可能會超時。 需要保持狀態,這對于功能是不希望的,因為它們需要是無狀態的。 耐用函數提供了內置的API,這些API簡化了您編寫的代碼以與長時間運行的函數執行進行交互。 此外,狀態由“持久功能”運行時管理。

//HTTP-triggered function to start a new orchestrator function instance.
public static async Task<HttpResponseMessage> Run (
HttpReq uestMessage req, DurableOrchestrationClient starter,
string functionName,
Ilogger log)
{
//Function name comes from the request URL.
//Function input comes from the request content .
dynamic eventData await req.Content .ReadAsAsync<object>();
string instanceid = await starter.StartNewAsync (functionName , eventData);
log .Loginformation ($”Started orchestration with ID = ‘{instanceid} ‘.”);
return starter.CreateCheckStatusResponse (req, instanceid);
}

演員們 (Actors)

Another use is the watcher — a recurring process in a workflow such as a clean-up process. You can put this in place with a function. But, again, you will have some challenges:

觀察者的另一個用途是觀察者-工作流中的重復過程,例如清理過程。 您可以使用函數將其放置到位。 但是,再次,您將面臨一些挑戰:

  • functions are stateless and short-lived

    功能是無狀態的,且存在時間短
  • read/write access to an external state needs to be synchronized

    對外部狀態的讀/寫訪問需要同步

With Durable Functions, you can have flexible recurrence intervals, task lifetime management, and the ability to create many watch processes from a single orchestration.

使用耐用功能,您可以具有靈活的重復間隔,任務生命周期管理以及從單個業務流程創建許多監視流程的能力。

public static async Task Run(DurableOrchestrationContext ctx)
{
int counterState = ctx.Getinput<int>();
string operation = await ctx.WaitForExternalEvent<string>(“operation”);
if (operation == “incr”)
{
counterState++;
}
else if (operation == “decr”)
{
counterstate --;
}
ctx.ContinueAsNew(counterState);
}

人際交往 (Human interaction)

Within organizations, you will face processes that require some human interaction such as approvals. Interactions like approvals require the availability of the approver. Thus, the process needs to be active for some time, and needs a reliable mechanism when the process times out. For instance, when an approval doesn’t occur within 72 hours, an escalation process must start. With Durable Functions, you can support such a scenario.

在組織內部,您將面臨需要人工交互(例如批準)的流程。 諸如批準之類的交互需要批準者的可用性。 因此,該過程需要在一段時間內處于活動狀態,并且在過程超時時需要可靠的機制。 例如,如果72小時之內未獲得批準,則必須啟動升級程序。 使用持久功能,您可以支持這種情況。

public static async Task Run(DurableOrchestrationContext ctx)
{
await ctx.CallFunctionAsync<object []>(“RequestApproval”);
using (var timeoutCts = new CancellationTokenSource())
{
DateTime dueTime = ctx.CurrentUtcDateTime.AddHours(72);
Task durableTimeout = ctx.CreateTimer(dueTime, 0, cts.Token);
Task<bool > approvalEvent = ctx.WaitForExternalEvent< bool>(“ApprovalEvent”);
if (approvalEvent == await Task .WhenAny(approvalEvent, durableTimeout ))
{
timeoutCts.Cancel();
await ctx .CallFunctionAsync(“HandleApproval”, approvalEvent.Result);
}
else
{
await ctx.CallFunctionAsy nc(“Escalate” );
}
}
}

示例實現:使用持久函數進行鏈接 (Sample implementation: Chaining using Durable Functions)

The Orchestrator Client is a function that can be triggered when a message is sent. This Client, a function, will call the Orchestrator and pass the order message.

Orchestrator客戶端是可以在發送消息時觸發的功能。 該客戶端是一個函數,它將調用Orchestrator并傳遞訂單消息。

public static async Task<HttpResponseMessage> Run (
HttpReq uestMessage req, DurableOrchestrationClient starter, string functionName,
Ilogger log)
{
//Function name comes from the request URL.
//Function input comes from the request content .
dynamic eventData await req.Content .ReadAsAsync<object>();
string instanceid = await starter.StartNewAsync ( functionName , eventData);
log .Loginformation ($”Started orchestration with ID = ‘{instanceid} ‘.”);
return starter.CreateCheckStatusResponse (req, instanceid);
}

The Orchestrator will receive the order and call the activity functions.

協調器將接收訂單并調用活動功能。

public static async Task Run(DurableOrchestrationContext context, object order, ILogger log)
{
log.LogInformation($”Data = ‘{order}’.”);
var orderDetail = (OrderDetail) order;
try
{
bool x = await context.CallActivityAsync<bool>(“WriteToDatabase”, orderDetail);
log.LogInformation($”Data storage = ‘{x}’.”);
if (x == true)
{
await context.CallActivityAsync<OrderDetail>(“WriteToArchive”, orderDetail);
await context.CallActivityAsync<OrderDetail>(“SendNotification”, orderDetail);
}
}
catch (Exception)
{
//ErrorHandling
}
}

Each of the activity functions will perform a task — in this case, store the order in a document collection in a CosmosDB instance, archive the stored message, and send a message to the queue to send out a notification via a logic app.

每個活動功能都將執行一項任務-在這種情況下,將訂單存儲在CosmosDB實例中的文檔集中,將已存儲的消息存檔,然后將消息發送到隊列以通過邏輯應用程序發出通知。

最佳實踐 (Best practices)

With Durable Functions there are a few best practices to follow:

使用耐用功能,可以遵循一些最佳做法:

  • use the Azure App Insights app to monitor running instances and health, including Azure Functions

    使用Azure App Insights應用程序監視正在運行的實例和運行狀況,包括Azure功能
  • the Durable Functions app also exposes the HTTP API for management. With the API methods, you can influence the course of action for your Durable Functions.

    耐用功能應用程序還公開了HTTP API進行管理。 使用API??方法,您可以影響耐用功能的操作過程。
  • use version control with your durable function

    與持久功能一起使用版本控制
  • you can use side-by-side deployment, updating the name of your task hub on deployment. See Durable Functions Blue Green Deployment Strategies for more information.

    您可以使用并行部署,在部署時更新任務中心的名稱。 有關更多信息,請參見持久功能藍綠色部署策略 。

結語 (Wrap-up)

In this blog post, we hope you have a better understanding of the use of Durable Functions, and what value they offer. Durable Functions give you the ultimate control over a workflow, not achievable with alternative technologies such as logic apps or functions alone. Together with some of the best practices we consolidated, you should now be able to build sustainable solutions with Durable Functions.

在本博客中,我們希望您對耐用功能的使用以及它們提供的價值有更好的了解。 耐用的功能為您提供了對工作流程的最終控制,這是僅使用邏輯應用程序或功能等替代技術無法實現的。 加上我們整合的一些最佳實踐,您現在應該能夠使用耐用功能構建可持續的解決方案。

This article was originally published at Serverless360.

本文最初在Serverless360上發布。

翻譯自: https://www.freecodecamp.org/news/an-introduction-to-azure-durable-functions-patterns-and-best-practices-b1939ae6c717/

azure多功能成像好用嗎

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/392696.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/392696.shtml
英文地址,請注明出處:http://en.pswp.cn/news/392696.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

leetcode 327. 區間和的個數(treemap)

給定一個整數數組 nums&#xff0c;返回區間和在 [lower, upper] 之間的個數&#xff0c;包含 lower 和 upper。 區間和 S(i, j) 表示在 nums 中&#xff0c;位置從 i 到 j 的元素之和&#xff0c;包含 i 和 j (i ≤ j)。 說明: 最直觀的算法復雜度是 O(n2) &#xff0c;請在此…

常用的工具函數

得到兩個數組的并集, 兩個數組的元素為數值或字符串//tools.js export const getUnion (arr1, arr2) > {return Array.from(new Set([...arr1, ...arr2])) }//調用頁面 import { getUnion } from /libs/toolsthis.getUnion getUnion([1,2,3,5],[1,4,6]) //(6) [1, 2, 3,…

git 常用commands(轉)

常用 Git 命令清單 作者&#xff1a; 阮一峰 日期&#xff1a; 2015年12月 9日 我每天使用 Git &#xff0c;但是很多命令記不住。 一般來說&#xff0c;日常使用只要記住下圖6個命令&#xff0c;就可以了。但是熟練使用&#xff0c;恐怕要記住60&#xff5e;100個命令。 下面是…

Win2003磁盤分區調整

引用如下&#xff1a; 可能大家都知道&#xff0c;在Windows Server 2003下&#xff0c;普通版本的分區魔術師是無法運行的&#xff0c;而Windows內置的命令行工具Diskpart則能勝任分區魔術師的大部分工作&#xff0c;它的功能非常強大。輸入Diskpart后&#xff0c;將顯示如圖所…

檢查集群狀態命令_輕松管理Kubernetes集群的7個工具

Kubernetes正在不斷加快在云原生環境的應用&#xff0c;但如何以統一、安全的方式對運行于任何地方的Kubernetes集群進行管理面臨著挑戰&#xff0c;而有效的管理工具能夠大大降低管理的難度。K9sk9s是基于終端的資源儀表板。它只有一個命令行界面。無論在Kubernetes儀表板Web …

leetcode 122. 買賣股票的最佳時機 II(貪心算法)

給定一個數組&#xff0c;它的第 i 個元素是一支給定股票第 i 天的價格。 設計一個算法來計算你所能獲取的最大利潤。你可以盡可能地完成更多的交易&#xff08;多次買賣一支股票&#xff09;。 注意&#xff1a;你不能同時參與多筆交易&#xff08;你必須在再次購買前出售掉…

前端繪制繪制圖表_繪制圖表(第2頁):JavaScript圖表庫的比較

前端繪制繪制圖表by Mandi Cai蔡曼迪 繪制圖表(第2頁)&#xff1a;JavaScript圖表庫的比較 (Charting the waters (pt. 2): a comparison of JavaScript charting libraries) 深入研究D3.js&#xff0c;Dygraphs&#xff0c;Chart.js和Google Charts (A deep dive into D3.js,…

python 3.6.5 pip_在Windows 10 + Python 3.6.5 中用 pip 安裝最新版 TensorFlow v1.8 for GPU

聲明什么cuDNN之類的安裝&#xff0c;應該是毫無難度的&#xff0c;按照官網的教程來即可&#xff0c;除非。。。像我一樣踩了狗屎運。咳咳&#xff0c;這些問題不是本文的關鍵。本文的關鍵是解決pip安裝tensorflow gpu版的問題。安裝環境操作系統&#xff1a;64位的Windows 10…

模板進階——模板實參推斷

一、關鍵點 模板實參&#xff1a;模板參數T的實例類型&#xff0c;如int、string等 模板實參推斷&#xff1a;從函數實參來確定模板實參的過程 模板類型參數與類型轉換&#xff1a;const的轉換、數組/函數到指針的轉換 顯式模板實參&#xff1a;當模板參數類型并未出現在函數參…

leetcode 973. 最接近原點的 K 個點(排序)

我們有一個由平面上的點組成的列表 points。需要從中找出 K 個距離原點 (0, 0) 最近的點。 &#xff08;這里&#xff0c;平面上兩點之間的距離是歐幾里德距離。&#xff09; 你可以按任何順序返回答案。除了點坐標的順序之外&#xff0c;答案確保是唯一的。 示例 1&#xf…

ios 打開揚聲器

[[UIDevice currentDevice] setProximityMonitoringEnabled:YES]; AVAudioSession *audioSession [AVAudioSession sharedInstance]; //默認情況下揚聲器播放 [audioSession setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthe…

sqlserver 批量處理數據

目前我覺得有兩種方法可以用作批量數據的處理&#xff0c;也算比較靠譜的吧&#xff1a;sqlbulkcopy 和利用表值函數。 1.sqlbulkcopy是dotnet中的一個用來處理大批量插入數據的&#xff0c;具體用法如下&#xff1a; using (SqlConnection conSave new SqlConnection(Config.…

區塊鏈編程語言_區塊鏈開發中使用的最受歡迎的編程語言

區塊鏈編程語言by Michael Draper通過邁克爾德雷珀(Michael Draper) We’re currently in the midst of a new burgeoning industry with blockchain development.我們目前正處于區塊鏈開發的新興行業中。 Blockchain technology is very much in a nascent stage, however t…

vscode 模糊部分代碼_本周 GitHub 速覽:您的代碼有聲兒嗎?(Vol.38)

作者&#xff1a;HelloGitHub-小魚干摘要&#xff1a;還記得花式夸贊程序員的彩虹屁插件 vscode-rainbow-fart 嗎&#xff1f;它后續有人啦&#xff01;JazzIt 同它的前輩 vscode-rainbow-fart 一樣&#xff0c;是一個能讓代碼“發聲”的工具&#xff0c;它會在腳本運行成功或者…

有趣的鏈接

1行命令實現人臉識別&#xff1a;https://linux.cn/article-9003-1.html轉載于:https://blog.51cto.com/10704527/1983007

webpack基礎使用Loader(三)

loaders:[ { test:/\.js$/, loader:babel-loader, exclude:__dirname"/node_modules/", //排除打包的范圍&#xff08;需要絕對路徑&#xff09; include:__dirname"src",//指定打包的范圍&#xff08;需要絕對路徑&#xff09; query:{ …

Flutter VS React Native –為什么我認為Flutter最適合移動應用程序開發

This isn’t the type of article you might think it’s going to be. I’m not going to list the pros and cons of every framework and I am not going to do a comparative analysis of performance. 這不是您可能會想到的文章類型。 我不會列出每個框架的優缺點&#xf…

python 2.7 error: Microsoft Visual C++ 9.0 is required

參考&#xff1a;https://stackoverflow.com/questions/43645519/microsoft-visual-c-9-0-is-required 解決方法&#xff1a; 下載并安裝Microsoft Visual C Compiler for Python 2.7&#xff1a; Microsoft Visual C Compiler for Python 2.7 轉載于:https://www.cnblogs.com/…

python內置支持集合運算嗎_Python中的集合支持交、并運算

Python中的集合支持交、并運算答&#xff1a;√新冠肺炎患者潛伏期的傳染性最強答&#xff1a;對在運動的組接中&#xff0c;鏡頭組接一個基本的原則是()、()。答&#xff1a;動接動 靜接靜在中指背,距指甲根中點1分許稱答&#xff1a;老龍庫存控制屬于生產管理而不是物流管理的…

C語言遞歸實現二叉樹(二叉鏈表)的三種遍歷和銷毀操作(實驗)

今天寫的是二叉樹操作的實驗&#xff0c;這個實驗有三個部分&#xff1a; ①建立二叉樹&#xff0c;采用二叉鏈表結構 ②先序、中序、后續遍歷二叉樹&#xff0c;輸出節點值 ③銷毀二叉樹 二叉樹的節點結構定義 typedef struct BiTNode //二叉樹的節…