Notitie
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen u aan te melden of de directory te wijzigen.
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen de mappen te wijzigen.
Orchestrator functies kunnen andere orchestrator functies aanroepen als sub-orchestrations. Een suborchestratie wordt uitgevoerd als kind van de aanroepende (ouder) orchestrator en gedraagt zich als een activiteit vanuit het perspectief van de beller: het kan een waarde teruggeven, uitzonderingen opwerpen die door de ouder zijn opgevangen en automatische nieuwe pogingen ondersteunen.
Wanneer sub-orkestraties worden gebruikt
Gebruik sub-orkestraties wanneer u het nodig heeft:
- Bouwblokken voor herbruikbare werkstromen opstellen: Extraheer een werkstroom met meerdere stappen naar een eigen orkestrator, zodat meerdere bovenliggende orkestraties deze kunnen aanroepen.
- Parallel uitwaaierindelingen: Plan veel exemplaren van dezelfde orchestrator gelijktijdig en wacht totdat ze allemaal zijn voltooid.
- Complexe werkstromen organiseren: Breek een grote indeling in benoemde, testbare stukken in plaats van één lange functie.
Opmerking
Sub-orkestraties moeten in dezelfde app worden gedefinieerd als de hoofdorkestratie. Als u orchestraties in een andere app wilt aanroepen, gebruikt u in plaats van het HTTP 202-pollingpatroon. Zie HTTP-functies voor meer informatie.
In dit artikel:
- Een subindeling definiëren - Voorbeeld van inrichting met één apparaat
- Suborchestraties parallel uitvoeren — fan-outpatroon met deterministische exemplaar-ID's
Opmerking
In PowerShell worden sub-orkestraties alleen ondersteund in de zelfstandige SDK: AzureFunctions.PowerShell.Durable.SDK. Zie de migratiehandleiding voor de verschillen tussen de zelfstandige SDK en de verouderde ingebouwde SDK.
Een suborkestratie definiëren
In het volgende voorbeeld ziet u een IoT-scenario waarin meerdere apparaten moeten worden ingesteld. De functie vertegenwoordigt de installatiewerkstroom die voor elk apparaat wordt uitgevoerd:
Geïsoleerd werkermodel
public static async Task DeviceProvisioningOrchestration(
[OrchestrationTrigger] TaskOrchestrationContext context, string deviceId)
{
// Step 1: Create an installation package in blob storage and return a SAS URL.
Uri sasUrl = await context.CallActivityAsync<Uri>("CreateInstallationPackage", deviceId);
// Step 2: Notify the device that the installation package is ready.
await context.CallActivityAsync("SendPackageUrlToDevice", (deviceId, sasUrl));
// Step 3: Wait for the device to acknowledge that it has downloaded the new package.
await context.WaitForExternalEvent<bool>("DownloadCompletedAck");
// Step 4: ...
}
Model tijdens het proces
public static async Task DeviceProvisioningOrchestration(
[OrchestrationTrigger] IDurableOrchestrationContext context)
{
string deviceId = context.GetInput<string>();
// Step 1: Create an installation package in blob storage and return a SAS URL.
Uri sasUrl = await context.CallActivityAsync<Uri>("CreateInstallationPackage", deviceId);
// Step 2: Notify the device that the installation package is ready.
await context.CallActivityAsync("SendPackageUrlToDevice", Tuple.Create(deviceId, sasUrl));
// Step 3: Wait for the device to acknowledge that it has downloaded the new package.
await context.WaitForExternalEvent<bool>("DownloadCompletedAck");
// Step 4: ...
}
using Microsoft.DurableTask;
[DurableTask]
public class DeviceProvisioningOrchestration : TaskOrchestrator<string, object?>
{
public override async Task<object?> RunAsync(TaskOrchestrationContext context, string deviceId)
{
// Step 1: Create an installation package in blob storage and return a SAS URL.
Uri sasUrl = await context.CallActivityAsync<Uri>("CreateInstallationPackage", deviceId);
// Step 2: Notify the device that the installation package is ready.
await context.CallActivityAsync("SendPackageUrlToDevice", (deviceId, sasUrl.ToString()));
// Step 3: Wait for the device to acknowledge that it has downloaded the new package.
await context.WaitForExternalEvent<bool>("DownloadCompletedAck");
// Step 4: ...
return null;
}
}
Deze orchestratorfunctie kan zelfstandig worden uitgevoerd voor het eenmalig instellen van een apparaat, of een bovenliggende orchestrator kan deze als suborkestratie inplannen met behulp van de call-sub-orchestrator API.
Suborkestraties parallel uitvoeren
In het volgende voorbeeld ziet u een bovenliggende orchestrator die meerdere subindelingen parallel uitgeeft. Sommige talen gebruiken een deterministische kindexemplaar-id (afgeleid van de bovenliggende exemplaar-id plus een index) om dubbele sub-orkestraties bij opnieuw afspelen te voorkomen.
Geïsoleerd werkermodel
[Function("ProvisionNewDevices")]
public static async Task ProvisionNewDevices(
[OrchestrationTrigger] TaskOrchestrationContext context)
{
string[] deviceIds = await context.CallActivityAsync<string[]>("GetNewDeviceIds");
// Run multiple device provisioning flows in parallel
var provisioningTasks = new List<Task>();
foreach (string deviceId in deviceIds)
{
Task provisionTask = context.CallSubOrchestratorAsync("DeviceProvisioningOrchestration", deviceId);
provisioningTasks.Add(provisionTask);
}
await Task.WhenAll(provisioningTasks);
// ...
}
Model tijdens het proces
[FunctionName("ProvisionNewDevices")]
public static async Task ProvisionNewDevices(
[OrchestrationTrigger] IDurableOrchestrationContext context)
{
string[] deviceIds = await context.CallActivityAsync<string[]>("GetNewDeviceIds");
// Run multiple device provisioning flows in parallel
var provisioningTasks = new List<Task>();
foreach (string deviceId in deviceIds)
{
Task provisionTask = context.CallSubOrchestratorAsync("DeviceProvisioningOrchestration", deviceId);
provisioningTasks.Add(provisionTask);
}
await Task.WhenAll(provisioningTasks);
// ...
}
Volgende stappen
using Microsoft.DurableTask;
[DurableTask]
public class ProvisionNewDevices : TaskOrchestrator<object?, object?>
{
public override async Task<object?> RunAsync(TaskOrchestrationContext context, object? input)
{
string[] deviceIds = await context.CallActivityAsync<string[]>("GetNewDeviceIds");
// Run multiple device provisioning flows in parallel
var provisioningTasks = new List<Task>();
foreach (string deviceId in deviceIds)
{
Task provisionTask = context.CallSubOrchestratorAsync("DeviceProvisioningOrchestration", deviceId);
provisioningTasks.Add(provisionTask);
}
await Task.WhenAll(provisioningTasks);
return null;
}
}