Soru

Zorluk: OrtaImplement Durable Functions

You are designing a serverless workflow using Azure Durable Functions in C# (.NET Isolated) to manage a vehicle fleet maintenance process. The orchestrator function must query an external vehicle diagnostics REST API to retrieve real-time fault codes before deciding which maintenance tasks to execute.

Which of the following is the correct way to implement this external API call while complying with the determinism requirements of Durable Functions?

  1. Delegate the REST API call to an Activity function called by the orchestrator, or use the orchestration context's built-in HTTP APIs.Cevap
  2. B
    Use the HttpClient class inside a Task.Run block to execute the API call asynchronously within the orchestrator.
  3. C
    Define a static HttpClient instance and perform an asynchronous GetAsync call directly in the orchestrator method.
  4. D
    Upgrade the hosting plan of the Function App to a Premium App Service plan to permit outbound HTTP calls from the orchestrator.

Cevap

Delegate the REST API call to an Activity function called by the orchestrator, or use the orchestration context's built-in HTTP APIs.
The correct answer is to delegate the REST API call to an Activity function or use the orchestration context's built-in HTTP APIs. Since orchestrator functions in Durable Functions must be completely deterministic, performing direct I/O (such as invoking external APIs via HttpClient) is not allowed. Activity functions do not have this restriction and are only executed once, with their results recorded in the execution history. Alternatively, the built-in CallHttpAsync method on the orchestration context can be used as it is designed to run deterministically during replays.

Adım Adım Çözüm

1
Identify the constraints of the Durable Functions orchestrator code.
Orchestrator code must be deterministic, meaning it cannot execute side effects or I/O operations directly.
During execution, the orchestrator is replayed multiple times from the history log. Any direct network calls would be re-executed, causing performance issues and non-deterministic behavior.
2
Determine the correct mechanism for calling external HTTP services.
External calls must either be placed inside an Activity function (which does not have determinism constraints) or executed using the built-in HTTP action APIs provided by the orchestration context (e.g., CallHttpAsync in .NET Isolated).
Activity functions execute once and record their output in the orchestration history, preventing re-execution during replays. The built-in CallHttpAsync API also registers its results in the orchestration history.

Anahtar Kavram

Orchestrator determinism and out-of-process communication using Activity functions or built-in HTTP APIs
Bu soruyu puanla