Example - Query State Store
This example demonstrates the State Store Query Alpha API in Dapr. It demonstrates the following APIs:
- querystatealpha1: Queries a compatible Dapr state store
Note: Make sure to use the latest proto bindings
Pre-requisites
Install Dapr python-SDK
pip3 install dapr dapr-ext-grpc
Store the configuration in configurationstore
docker run -d --rm -p 27017:27017 --name mongodb mongo:5
Run the example
Change directory to this folder:
cd examples/state_store_queryTo run this example, start by importing the test data
# Import the example dataset dapr run --app-id demo --dapr-http-port 3500 --resources-path components -- curl -X POST -H "Content-Type: application/json" -d @dataset.json http://localhost:3500/v1.0/state/statestore
Now run the app
dapr run --app-id queryexample --resources-path components/ -- python3 state_store_query.py
You should be able to see the following output:
1 {"city": "Seattle", "person": {"id": 1036.0, "org": "Dev Ops"}, "state": "WA"}
4 {"city": "Spokane", "person": {"id": 1042.0, "org": "Dev Ops"}, "state": "WA"}
10 {"city": "New York", "person": {"id": 1054.0, "org": "Dev Ops"}, "state": "NY"}
Token: 3
9 {"city": "San Diego", "person": {"id": 1002.0, "org": "Finance"}, "state": "CA"}
7 {"city": "San Francisco", "person": {"id": 1015.0, "org": "Dev Ops"}, "state": "CA"}
3 {"city": "Sacramento", "person": {"id": 1071.0, "org": "Finance"}, "state": "CA"}
Token: 6
Cleanup