Signed-off-by: Marc Duiker <marcduiker@users.noreply.github.com> |
||
---|---|---|
.. | ||
fan_out_fan_in | ||
README.md | ||
dapr.yaml | ||
fanoutfanin.http | ||
makefile |
README.md
Fan-out/Fan-in
This tutorial demonstrates how to author a workflow where multiple independent tasks can be scheduled and executed simultaneously. The workflow can either wait until all tasks are completed to proceed, or continue when the fastest task is completed. For more information about the fan-out/fan-in pattern see the Dapr docs.
Inspect the code
Open the fanoutfanin_workflow.py
file in the tutorials/workflow/python/fan-out-fan-in/fan_out_fan_in
folder. This file contains the definition for the workflow.
graph LR
SW((Start
Workflow))
subgraph for each word in the input
GWL[get_word_length]
end
SHORT[Select the
shortest word]
ALL[Wait until all tasks
are completed]
EW((End
Workflow))
SW --> GWL
GWL --> ALL
ALL --> SHORT
SHORT --> EW
Run the tutorial
-
Use a terminal to navigate to the
tutorials/workflow/python/fan-out-fan-in/fan_out_fan_in
folder. -
Install the dependencies using pip:
pip3 install -r requirements.txt
-
Navigate back one level to the
fan-out-fan-in
folder and use the Dapr CLI to run the Dapr Multi-App run file```bash
dapr run -f .
<!-- END_STEP -->
-
Use the POST request in the
fanoutfanin.http
file to start the workflow, or use this cURL command:curl -i --request POST \ --url http://localhost:5256/start \ --header 'content-type: application/json' \ --data '["which","word","is","the","shortest"]'
The input for the workflow is an array of strings:
[ "which", "word", "is", "the", "shortest" ]
The expected app logs are as follows:
== APP - fanoutfanin == get_word_length: Received input: word. == APP - fanoutfanin == get_word_length: Received input: is. == APP - fanoutfanin == get_word_length: Received input: the. == APP - fanoutfanin == get_word_length: Received input: shortest. == APP - fanoutfanin == get_word_length: Received input: which.
Note that the order of the logs may vary.
-
Use the GET request in the
fanoutfanin.http
file to get the status of the workflow, or use this cURL command:curl --request GET --url http://localhost:3556/v1.0/workflows/dapr/<INSTANCEID>
Where
<INSTANCEID>
is the workflow instance ID you received in theinstance_id
property in the previous step.The expected serialized output of the workflow is:
"\"is\""
-
Stop the Dapr Multi-App run process by pressing
Ctrl+C
.