mukundansundar / svc-invoke-dapr-python

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Microservice communication using service invoke (sync)

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.

Run and develop locally

Run the order-processor service (callee) with Dapr

  1. Open a new terminal window, change directories to ./order-processor and run:
cd order-processor
pip3 install -r requirements.txt 
  1. 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

Run the checkout service (caller) with Dapr

  1. Open a new terminal window, change directories to ./checkout and run:
cd checkout
pip3 install -r requirements.txt 
  1. Run the checkout service (callee) with Dapr:
dapr run  --app-id checkout --app-protocol http --dapr-http-port 3500 -- python3 app.py
  1. 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 (Azure Container Apps)

Deploy to Azure for dev-test

NOTE: make sure you have Azure Dev CLI pre-reqs here

  1. Provision infra and deploy application:
azd up
  1. 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.

About

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


Languages

Language:Bicep 96.9%Language:Dockerfile 1.8%Language:Python 1.2%Language:Makefile 0.1%