page_type | languages | products | urlFragment | name | description | |||||
---|---|---|---|---|---|---|---|---|---|---|
sample |
|
|
svc-invoke-dapr-python |
Microservice communication using Dapr's Service Invocation API (Python) |
Create two microservices with Python that communicate using Dapr's Service Invocation API. The Service Invocation API enables your applications to communicate reliably and securely by leveraging auto-mTLS and built-in retries |
In this quickstart, you'll create two microservices that communicate using Dapr's Service Invocation API. The Service Invocation API enables your applications to communicate reliably and securely by leveraging auto-mTLS and built-in retries.
Visit this link for more information about Dapr and Service Invocation.
- Open a new terminal window, change directories to
./order-processor
and run:
cd order-processor
pip3 install -r requirements.txt
- Run the order-processor service (callee) with Dapr:
dapr run --app-port 8001 --app-id order-processor --app-protocol http --dapr-http-port 3501 -- python3 app.py
- Open a new terminal window, change directories to
./checkout
and run:
cd checkout
pip3 install -r requirements.txt
- Run the checkout service (callee) with Dapr:
dapr run --app-id checkout --app-protocol http --dapr-http-port 3500 -- python3 app.py
- Expected output: In both terminals, you'll see orders passed and orders received. Service invocation requests are made from the checkout service to the order-processor service:
Output from the checkout service:
== APP == Order passed: {"orderId":1}
== APP == Order passed: {"orderId":2}
== APP == Order passed: {"orderId":3}
== APP == Order passed: {"orderId":4}
Output from the order-processor service:
== APP == Order received: { orderId: 1 }
== APP == Order received: { orderId: 2 }
== APP == Order received: { orderId: 3 }
== APP == Order received: { orderId: 4 }
Deploy to Azure for dev-test
NOTE: make sure you have Azure Dev CLI pre-reqs here and are on version 0.9.0-beta.3 or greater.
- Run the following command to initialize the project.
azd init --template https://github.com/Azure-Samples/svc-invoke-dapr-python
This command will clone the code to your current folder and prompt you for the following information:
Environment Name
: This will be used as a prefix for the resource group that will be created to hold all Azure resources. This name should be unique within your Azure subscription.
- Run the following command to package a deployable copy of your application, provision the template's infrastructure to Azure and also deploy the application code to those newly provisioned resources.
azd up
This command will prompt you for the following information:
Azure Location
: The Azure location where your resources will be deployed.Azure Subscription
: The Azure Subscription where your resources will be deployed.
NOTE: This may take a while to complete as it executes three commands:
azd package
(packages a deployable copy of your application),azd provision
(provisions Azure resources), andazd deploy
(deploys application code). You will see a progress indicator as it packages, provisions and deploys your application.
- Confirm the deployment is susccessful:
Navigate to the Container App resources for both the Checkout and Order-Processor services. Locate the Log stream
and confirm the app container is logging each request successfully.