In this QuickStart, you will run a microservice application that continuously persists and retrieves state via Dapr's state management API. When operations to the state store begin to fail, Dapr resiliency policies are applied.
Visit the documentation about Dapr resiliency link for more information
This quickstart includes one service:
- Client service
order-processor
- Redis component spec
statestore.yaml
- Resiliency spec
resiliency.yaml
- Navigate to the app directory, install dependencies, and run the service with resiliency:
cd ../state_management/csharp/sdk/order-processor
dotnet restore
dotnet build
dapr run --app-id order-processor --resources-path ../../../resources/ -- dotnet run
cd ../state_management/go/sdk/order-processor
go build .
dapr run --app-id order-processor --resources-path ../../../resources -- go run .
cd ../state_management/java/sdk/order-processor
mvn clean install
dapr run --app-id order-processor --resources-path ../../../resources/ -- java -jar target/OrderProcessingService-0.0.1-SNAPSHOT.jar
cd ../state_management/javascript/sdk/order-processor
npm install
dapr run --app-id order-processor --resources-path ../../../resources/ -- npm start
cd ../state_management/python/sdk/order-processor
pip3 install -r requirements.txt
dapr run --app-id order-processor --resources-path ../../../resources/ -- python3
== APP == Saving Order: { orderId: '1' }
== APP == Getting Order: { orderId: '1' }
== APP == Saving Order: { orderId: '2' }
== APP == Getting Order: { orderId: '2' }
== APP == Saving Order: { orderId: '3' }
== APP == Getting Order: { orderId: '3' }
== APP == Saving Order: { orderId: '4' }
== APP == Getting Order: { orderId: '4' }
In a new terminal window, stop the Redis container that's running on your machine:
docker stop dapr_redis
Policies defined in the resiliency.yaml spec:
retryForever:
policy: constant
duration: 5s
maxRetries: -1
circuitBreakers:
simpleCB:
maxRequests: 1
timeout: 5s
trip: consecutiveFailures >= 5
Applied policies:
INFO[0006] Error processing operation component[statestore] output. Retrying...
INFO[0026] Circuit breaker "simpleCB-statestore" changed state from closed to open
INFO[0031] Circuit breaker "simpleCB-statestore" changed state from open to half-open
INFO[0031] Circuit breaker "simpleCB-statestore" changed state from half-open to open
docker start dapr_redis
INFO[0036] Recovered processing operation component[statestore] output.
== APP == Saving Order: { orderId: '5' }
== APP == Getting Order: { orderId: '5' }
== APP == Saving Order: { orderId: '6' }
== APP == Getting Order: { orderId: '6' }
== APP == Saving Order: { orderId: '7' }
== APP == Getting Order: { orderId: '7' }
== APP == Saving Order: { orderId: '8' }
== APP == Getting Order: { orderId: '8' }
== APP == Saving Order: { orderId: '9' }
== APP == Getting Order: { orderId: '9' }
dapr stop --app-id order-processor