- Durable Function ?
- Durable Function คือ การทำให้ Azure Function เป็น Stateful (ปกติแล้ว Azure Function จะเป็น Stateless)
- Durable Function การออกแบบ Flow ต้องเป็นแบบ deterministic (ไม่ว่าจะ Execute กี่รอบ ต้องได้ผลลัพธ์เหมือนกันทุกรอบ)
- ตัวอย่างการนำไปใช้
- Async HTTP APIs - สำหรับ Task ที่ใช้ระยะเวลานานในการประมวลผล ( long-running operations) อันนี้คล้ายๆกับ Flow ที่ผมออกแบบไว้ใน Java เลย เดี๋ยวว่างๆจะมาเขียน Blog แยกอีกตอนครับ

- Function chaining - ทำงานเป็น pipeline ตามลำดับ

- Fan-Out/ Fan-In - แต่งานให้ทำพร้อมกันได้ ถ้า C# จะเป็นพวก Parallel.ForEach

- Monitoring - ตรวจสอบ Task โดยเอามีส่ง Trigger เมื่อตรงตามเงื่อนไขที่กำหนดไว้ (polling a resource until a specific condition is met?)

- Human Interaction - สำหรับ Activity ที่ต้องการการตอบสนอง จากมนุษย์ เพื่อให้ Flow เดินต่อได้ครับ สำหรับ Pattern นี้มาคู่กับ Time Out เพื่อไม่ให้มีงานค้างในระบบ (ถ้ามันค้างเราเสียเงินแย่)

- Aggregator - เอาข้อมูลจากหลายแหล่งมาประมวลผลใน Azure Function และจัดเก็บลง Storage

- NOTE: ส่วนตัวผมมองว่า Durable Function == Executable BPMN อย่าง เช่น พวก Camunda
- ส่วนประกอบ Durable Functions:
- orchestrator -
- เป็นส่วน main ของ Flow โดยที่ logic ต้องเป็น deterministic
- ประกอบไปด้วย activity functions, sub-orchestrations
- Orchestrator functions have the ability to wait and listen for external events. This feature of Durable Functions is often useful for handling human interaction or other external triggers.
- activity - basic unit of work
- entity - operations for reading and updating small pieces of state
- client
- Task hub
- Task hub in Durable Functions is a logical container for durable storage resources that are used for orchestrations and entities. แต่ถ้ามี Function App หลายๆตัวต้องแยก Task Hub
- declared in the host.json
Knowledge Check: Implement Durable Functions (Knowledge Check)
Reference
Discover more from naiwaen@DebuggingSoft
Subscribe to get the latest posts sent to your email.