Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Azure-Samples/pubsub-dapr-csharp-servicebus
A complete microservice application featuring Dapr Pub-Sub, deployed to Azure Container Apps and Azure Service Bus Topics with dead-lettering support.
https://github.com/Azure-Samples/pubsub-dapr-csharp-servicebus
azd-templates azure dapr
Last synced: 4 months ago
JSON representation
A complete microservice application featuring Dapr Pub-Sub, deployed to Azure Container Apps and Azure Service Bus Topics with dead-lettering support.
- Host: GitHub
- URL: https://github.com/Azure-Samples/pubsub-dapr-csharp-servicebus
- Owner: Azure-Samples
- License: apache-2.0
- Created: 2022-07-11T18:37:05.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-07T02:02:48.000Z (8 months ago)
- Last Synced: 2024-07-29T17:04:26.552Z (6 months ago)
- Topics: azd-templates, azure, dapr
- Language: Bicep
- Homepage:
- Size: 270 KB
- Stars: 26
- Watchers: 14
- Forks: 17
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
---
page_type: sample
languages:
- azdeveloper
- csharp
- bicep
products:
- azure
- azure-container-apps
- azure-service-bus
urlFragment: pubsub-dapr-csharp-servicebus
name: Microservice communication using pubsub (async)(C#)
description: Create a publisher microservice and a subscriber microservice with C# to demonstrate how Dapr enables a publish-subcribe pattern. The publisher will generate messages of a specific topic, while subscribers will listen for messages of specific topics.
---# Microservice communication using pubsub (async)
![](images/pubsub-diagram.png)
In this quickstart, you'll create a publisher microservice and a subscriber microservice to demonstrate how Dapr enables a publish-subcribe pattern. The publisher will generate messages of a specific topic, while subscribers will listen for messages of specific topics. See [Why Pub-Sub](#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](https://docs.dapr.io/getting-started/quickstarts/pubsub-quickstart/).
Visit [this](https://docs.dapr.io/developing-applications/building-blocks/pubsub/) 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 [click here](../http).
This quickstart includes one publisher:
- Dotnet client message generator `checkout`
And one subscriber:
- Dotnet subscriber `order-processor`### Pre-requisites
For this example, you will need:
- [Dapr CLI](https://docs.dapr.io/getting-started)
- [.NET 6 SDK](https://dotnet.microsoft.com/download)- [Docker Desktop](https://www.docker.com/products/docker-desktop)
### Run Dotnet message subscriber with Dapr
1. Navigate to the directory and install dependencies:
```bash
cd ./order-processor
dotnet restore
dotnet build
```2. Run the Dotnet subscriber app with Dapr:
```bash
dapr run --app-id order-processor --components-path ../components/ --app-port 7001 -- dotnet run --project .
```### Run Dotnet message publisher with Dapr
3. Navigate to the directory and install dependencies:
```bash
cd ./checkout
dotnet restore
dotnet build
```4. Run the Dotnet publisher app with Dapr:
```bash
dapr run --app-id checkout --components-path ../components/ -- dotnet run --project .
``````bash
dapr stop --app-id order-processor
```### Deploy apps to Azure (Azure Container Apps, Azure Service Bus)
#### Deploy to Azure for dev-test
NOTE: make sure you have Azure Dev CLI pre-reqs [here](https://learn.microsoft.com/en-us/azure/developer/azure-developer-cli/install-azd?tabs=winget-windows%2Cbrew-mac%2Cscript-linux&pivots=os-windows) and are on version 0.9.0-beta.3 or greater.
5. Run the following command to initialize the project.
```bash
azd init --template https://github.com/Azure-Samples/pubsub-dapr-csharp-servicebus
```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.
6. 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.
```bash
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), and `azd deploy` (deploys application code). You will see a progress indicator as it packages, provisions and deploys your application.