docs: Updated read me files to use Java 17 as baseline Signed-off-by: amardeep2006 <amardeep2006@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 the lifecycle of a workflow that stores and retrieves data in a state store.
This quickstart includes one project:
- Java console app
order-processor
The quickstart contains 1 workflow to simulate purchasing items from a store, and 5 unique activities within the workflow. These 5 activities are as follows:
- NotifyActivity: 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.
- ReserveInventoryActivity: This activity checks the state store to ensure that there is enough inventory present for purchase.
- RequestApprovalActivity: This activity requests approval for orders over a certain threshold
- ProcessPaymentActivity: This activity is responsible for processing and authorizing the payment.
- UpdateInventoryActivity: This activity updates the state store with the new remaining inventory value.
Run the order processor workflow with multi-app-run
- Open a new terminal window and navigate to
order-processordirectory:
cd ./order-processor
mvn clean install
cd ..
- Run the console app with Dapr:
dapr run -f .
- Expected output
== APP - WorkflowConsoleApp == *** Welcome to the Dapr Workflow console app sample!
== APP - WorkflowConsoleApp == *** Using this app, you can place orders that start workflows.
== APP - WorkflowConsoleApp == Start workflow runtime
== APP - WorkflowConsoleApp == Oct 06, 2023 3:10:01 PM com.microsoft.durabletask.DurableTaskGrpcWorker startAndBlock
== APP - WorkflowConsoleApp == INFO: Durable Task worker is connecting to sidecar at 127.0.0.1:50001.
== APP - WorkflowConsoleApp == ==========Begin the purchase of item:==========
== APP - WorkflowConsoleApp == Starting order workflow, purchasing 10 of cars
== APP - WorkflowConsoleApp == scheduled new workflow instance of OrderProcessingWorkflow with instance ID: 397faa44-1374-4f9d-a7fe-c74160604064
== APP - WorkflowConsoleApp == [Thread-0] INFO io.dapr.workflows.WorkflowContext - Starting Workflow: io.dapr.quickstarts.workflows.OrderProcessingWorkflow
== APP - WorkflowConsoleApp == [Thread-0] INFO io.dapr.workflows.WorkflowContext - Instance ID(order ID): 397faa44-1374-4f9d-a7fe-c74160604064
== APP - WorkflowConsoleApp == [Thread-0] INFO io.dapr.workflows.WorkflowContext - Current Orchestration Time: 2023-10-06T22:10:04.769Z
== APP - WorkflowConsoleApp == [Thread-0] INFO io.dapr.workflows.WorkflowContext - Received Order: OrderPayload [itemName=cars, totalCost=150000, quantity=10]
== APP - WorkflowConsoleApp == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.NotifyActivity - Received Order: OrderPayload [itemName=cars, totalCost=150000, quantity=10]
== APP - WorkflowConsoleApp == workflow instance 397faa44-1374-4f9d-a7fe-c74160604064 started
== APP - WorkflowConsoleApp == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.ReserveInventoryActivity - Reserving inventory for order '397faa44-1374-4f9d-a7fe-c74160604064' of 10 cars
== APP - WorkflowConsoleApp == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.ReserveInventoryActivity - There are 100 cars available for purchase
== APP - WorkflowConsoleApp == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.ReserveInventoryActivity - Reserved inventory for order '397faa44-1374-4f9d-a7fe-c74160604064' of 10 cars
== APP - WorkflowConsoleApp == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.RequestApprovalActivity - Requesting approval for order: OrderPayload [itemName=cars, totalCost=150000, quantity=10]
== APP - WorkflowConsoleApp == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.RequestApprovalActivity - Approved requesting approval for order: OrderPayload [itemName=cars, totalCost=150000, quantity=10]
== APP - WorkflowConsoleApp == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.ProcessPaymentActivity - Processing payment: 397faa44-1374-4f9d-a7fe-c74160604064 for 10 cars at $150000
== APP - WorkflowConsoleApp == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.ProcessPaymentActivity - Payment for request ID '397faa44-1374-4f9d-a7fe-c74160604064' processed successfully
== APP - WorkflowConsoleApp == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.UpdateInventoryActivity - Updating inventory for order '397faa44-1374-4f9d-a7fe-c74160604064' of 10 cars
== APP - WorkflowConsoleApp == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.UpdateInventoryActivity - Updated inventory for order '397faa44-1374-4f9d-a7fe-c74160604064': there are now 90 cars left in stock
== APP - WorkflowConsoleApp == there are now 90 cars left in stock
== APP - WorkflowConsoleApp == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.NotifyActivity - Order completed! : 397faa44-1374-4f9d-a7fe-c74160604064
== APP - WorkflowConsoleApp == workflow instance completed, out is: {"processed":true}
View workflow output with Zipkin
For a more detailed view of the workflow activities (duration, progress etc.), try using Zipkin.
- Launch Zipkin container - The openzipkin/zipkin docker container is launched on running
dapr init. Check to make sure the container is running. If it's not, launch the Zipkin docker container with the following command.
docker run -d -p 9411:9411 openzipkin/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.
What happened?
When you ran dapr run --app-id WorkflowConsoleApp --resources-path ../../../components/ --dapr-grpc-port 50001 -- java -jar target/OrderProcessingService-0.0.1-SNAPSHOT.jar io.dapr.quickstarts.workflows.WorkflowConsoleApp
- A unique order ID for the workflow is generated (in the above example,
95d33f7c-3af8-4960-ba11-4ecea83b0509) and the workflow is scheduled. - The
NotifyActivityworkflow activity sends a notification saying an order for 10 cars has been received. - The
ReserveInventoryActivityworkflow activity checks the inventory data, determines if you can supply the ordered item, and responds with the number of cars in stock. - Your workflow starts and notifies you of its status.
- The
RequestApprovalActivityworkflow activity requests approval for order95d33f7c-3af8-4960-ba11-4ecea83b0509 - The
ProcessPaymentActivityworkflow activity begins processing payment for order95d33f7c-3af8-4960-ba11-4ecea83b0509and 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 order95d33f7c-3af8-4960-ba11-4ecea83b0509has completed and processed. - The workflow terminates as completed and processed.