mirror of https://github.com/dapr/quickstarts.git
Signed-off-by: Deepanshu Agarwal <deepanshu.agarwal1984@gmail.com> |
||
|---|---|---|
| .. | ||
| img | ||
| order-processor | ||
| README.md | ||
| dapr.yaml | ||
| makefile | ||
README.md
Dapr workflows
In this quickstart, you'll create a simple console application to demonstrate Dapr's workflow programming model and the workflow management API. The console app starts and manages an order processing workflow.
This quickstart includes one project:
- Python console app
order-processor
The quickstart contains 1 workflow (order_processing_workflow) which simulates purchasing items from a store, and 5 unique activities within the workflow. These 5 activities are as follows:
- notify_activity: This activity utilizes a logger to print out messages throughout the workflow. These messages notify the user when there is insufficient inventory, their payment couldn't be processed, and more.
- process_payment_activity: This activity is responsible for processing and authorizing the payment.
- verify_inventory_activity: This activity checks the state store to ensure that there is enough inventory present for purchase.
- update_inventory_activity: This activity removes the requested items from the state store and updates the store with the new remaining inventory value.
- requst_approval_activity: This activity seeks approval from Manager, if payment is greater than 50000 USD.
Run the order processor workflow
- Open a new terminal window and navigate to
order-processordirectory:
cd ./order-processor
pip3 install -r requirements.txt
cd ..
- Run the console app with Dapr:
dapr run -f .
- Expected output
==========Begin the purchase of item:==========
Starting order workflow, purchasing 10 of cars
INFO:NotifyActivity:Received order b903d749cd814e099f06ebf4a56a2f90 for 10 cars at $150000 !
INFO:VerifyInventoryActivity:Verifying inventory for order b903d749cd814e099f06ebf4a56a2f90 of 10 cars
INFO:VerifyInventoryActivity:There are 100 Cars available for purchase
INFO:RequestApprovalActivity:Requesting approval for payment of 150000 USD for 10 cars
INFO:NotifyActivity:Payment for order b903d749cd814e099f06ebf4a56a2f90 has been approved!
INFO:ProcessPaymentActivity:Processing payment: b903d749cd814e099f06ebf4a56a2f90 for 10 cars at 150000 USD
INFO:ProcessPaymentActivity:Payment for request ID b903d749cd814e099f06ebf4a56a2f90 processed successfully
INFO:UpdateInventoryActivity:Checking inventory for order b903d749cd814e099f06ebf4a56a2f90 for 10 cars
INFO:UpdateInventoryActivity:There are now 90 cars left in stock
INFO:NotifyActivity:Order b903d749cd814e099f06ebf4a56a2f90 has completed!
Workflow completed! Result: Completed
Purchase of item is Completed
- Stop Dapr workflow with CTRL-C or:
dapr stop -f .
View workflow output with Zipkin
For a more detailed view of the workflow activities (duration, progress etc.), try using Zipkin.
- View Traces in Zipkin UI - In your browser go to http://localhost:9411 to view the workflow trace spans in the Zipkin web UI. The order-processor workflow should be viewable with the following output in the Zipkin web UI. Note: the openzipkin/zipkin docker container is launched on running
dapr init.
What happened?
When you ran dapr run --app-id order-processor --resources-path ../../../components/ -- python3 app.py
- First the user inputs an order for 10 cars into the concole app.
- A unique order ID for the workflow is generated (in the above example,
b903d749cd814e099f06ebf4a56a2f90) and the workflow is scheduled. - The
NotifyActivityworkflow activity sends a notification saying an order for 10 cars has been received. - The
VerifyInventoryActivityworkflow activity checks the inventory data, determines if you can supply the ordered item, and responds with the number of cars in stock. - The
RequestApprovalActivityworkflow activity is triggered due to buisness logic for orders exceeding $50k and user is prompted to manually approve the purchase before continuing order. - The workflow starts and notifies you of its status.
- The
ProcessPaymentActivityworkflow activity begins processing payment for orderb903d749cd814e099f06ebf4a56a2f90and confirms if successful. - The
UpdateInventoryActivityworkflow activity updates the inventory with the current available cars after the order has been processed. - The
NotifyActivityworkflow activity sends a notification saying that orderb903d749cd814e099f06ebf4a56a2f90has completed. - The workflow terminates as completed.