A bunch of examples on how to publish and consume messages via Azure Service Bus broker.
Postmen has two groups of applications
One called Senders, can post messages into a Topic in Azure Service Bus. All these applications post messages to the same Topic called by default postcreated.
Other called Receivers, can receive posted messages throught a Topic Subscription. Each kind of application is connected to tis own subscription like:
Postmen.Receiver.Console.Core
listens postcreatedsubscriptioncore;Postmen.Receiver.Console.Framework
listens postcreatedsubscriptionframework;Postmen.Receiver.Functions
listens postcreatedsubscriptionfunctions;
To setup broker infrastructure:
# '~' is used to represent the project`s root folder
cd ~/src/environment
az login
terraform init
terraform apply
# to get broker connection string
terraform output BrokerConnectionString
.Net Framework apps uses environment variables to manage connection strings
Before run .Net Framework apps, it's necessary to configure local Environment Variables:
# <BrokerConnectionString> got from terraform execution
[System.Environment]::SetEnvironmentVariable('ConnectionStrings:ServiceBus','<BrokerConnectionString>')
.Net Core apps uses user secrets to manage connection strings.
Before run .Net Core apps, it's necessary to configure user secrets.
To do so, inside the .Net Core project folder:
# <BrokerConnectionString> got from terraform execution
dotnet user-secrets init
dotnet user-secrets set "ConnectionStrings:ServiceBus" "<BrokerConnectionString>"
Before run Azure Functions Apps, it's necessary to create a local configuration file - named local.settings.json
- inside the Azure Functions App project folder:
// File local.settings.json
// <BrokerConnectionString> got from terraform execution
{
//...
"Values": {
//...
"ServiceBusConnectionString": "<BrokerConnectionString>"
}
}
Notice that you probably wanna run at least one instance of senders and one of receivers. All senders and receivers are connected to the same single broker.
Just open the project in Visual Studio and start the application.
.Net Core apps have configuration to set the DOTNET_ENVIRONMENT
to Development so the user-secrets
mechanism can work correctly (check Properties/launchSettings.json
).
To run .Net Core apps you can open the application in Visual Studio or Visual Studio Code and hit run or, inside the project folder:
dotnet run
To run multiple instances of Azure Functions Apps locally, these projects where configure to use non default debug ports. Keep in mind that debuging Sender function will allocate 7072
and Receiver, 7073
.
To run Azure Functions Apps you can open the application in Visual Studio or Visual Studio Code and hit run or, insisde the project folder:
func start
- Terraform 1.0
- Free Azure Account (services used in this examples aren`t free)
- Azure CLI 2.28
Used to create these examples but completly optional: