In this quickstart, you'll create a microservice to demonstrate Dapr's bindings API to work with external systems as inputs and outputs. The service listens to input binding events from a system CRON and then outputs the contents of local data to a PostreSql output binding.
Visit this link for more information about Dapr and Bindings.
- Open a new terminal, change directories to
../../db
, and run the container with Docker Compose:
cd db/
docker compose up -d
- Open a new terminal window, change directories to
./batch
in the quickstart directory and run:
cd ../batch
pip install -r requirements.txt
- Run the Python service app with Dapr:
dapr run --app-id batch-sdk --app-port 5001 --dapr-http-port 3500 --components-path ../components -- python3 app.py
- Expected output: A batch script runs every 10 seconds using an input Cron binding. The script processes a JSON file and outputs data to a SQL database using the PostgreSQL Dapr binding:
== APP == {"sql": "insert into orders (orderid, customer, price) values (1, 'John Smith', 100.32);"}
== APP == {"sql": "insert into orders (orderid, customer, price) values (2, 'Jane Bond', 15.4);"}
== APP == {"sql": "insert into orders (orderid, customer, price) values (3, 'Tony James', 35.56);"}
== APP == Finished processing batch
== APP == {"sql": "insert into orders (orderid, customer, price) values (1, 'John Smith', 100.32);"}
== APP == {"sql": "insert into orders (orderid, customer, price) values (2, 'Jane Bond', 15.4);"}
== APP == {"sql": "insert into orders (orderid, customer, price) values (3, 'Tony James', 35.56);"}
== APP == Finished processing batch
== APP == {"sql": "insert into orders (orderid, customer, price) values (1, 'John Smith', 100.32);"}
== APP == {"sql": "insert into orders (orderid, customer, price) values (2, 'Jane Bond', 15.4);"}
== APP == {"sql": "insert into orders (orderid, customer, price) values (3, 'Tony James', 35.56);"}
== APP == Finished processing batch
- Stop postgres container
cd ../db
docker compose stop
Deploy to Azure for dev-test
NOTE: make sure you have Azure Dev CLI pre-reqs here
- Provision infra and deploy application:
azd up
- Confirm the deployment is susccessful:
Navigate to the Container App resource for the Batch service. Locate the Log stream
and confirm the batch container is logging each insert successfully every 10s.