In this quickstart, you'll create a publisher microservice and a subscriber microservice to demonstrate how Dapr enables a publish-subscribe pattern. The publisher will generate messages of a specific topic, while subscribers will listen for messages of specific topics. See Why Pub-Sub to understand when this pattern might be a good choice for your software architecture.
For more details about this quickstart example please see the Pub-Sub Quickstart documentation.
Visit this link for more information about Dapr and Pub-Sub.
Note: This example leverages the Dapr client SDK. If you are looking for the example using only HTTP
requests
click here.
The following prerequisites are required to use this application. Please ensure that you have them all installed locally.
- Azure Developer CLI
- Windows:
powershell -ex AllSigned -c "Invoke-RestMethod 'https://aka.ms/install-azd.ps1' | Invoke-Expression"
- Linux/MacOS:
curl -fsSL https://aka.ms/install-azd.sh | bash
- Windows:
- Azure CLI (2.37.0+)
- Dapr CLI.
- Latest Node.js (v14.16.1 +).
The fastest way for you to get this application up and running on Azure is to use the azd up
command. This single command will create and configure all necessary Azure & local resources.
Run the following command to initialize the project, provision the core Azure resources, build the application code in containers and push to a private Azure Container Registry to create a working application.
azd up -t pubsub-dapr-nodejs-servicebus
This sample includes one publisher:
- Node client message generator
checkout
And one subscriber:
- Node subscriber
order-processor
- Install dependencies in a new terminal:
cd ./order-processor
npm install
- Run the Node subscriber app with Dapr:
dapr run --app-port 5001 --app-id order-processing --app-protocol http --dapr-http-port 3501 --components-path ../components -- npm run start
- Install dependencies in a new terminal:
cd ./checkout
npm install
- Run the Node publisher app with Dapr:
dapr run --app-id checkout --app-protocol http --components-path ../components -- npm run start
dapr stop --app-id checkout
dapr stop --app-id order-processor
- Re-Deploy to Azure for dev-test
NOTE: make sure you have Azure Dev CLI pre-reqs here
azd deploy