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.mzph.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 //二叉树的节…