docs/en/framework/infrastructure/event-bus/distributed/azure.md
//[doc-seo]
{
"Description": "Learn how to integrate Azure Service Bus as a distributed event bus provider in your ABP Framework project with this comprehensive guide."
}
This document explains how to configure the Azure Service Bus as the distributed event bus provider. See the distributed event bus document to learn how to use the distributed event bus system
Use the ABP CLI to add Volo.Abp.EventBus.Azure NuGet package to your project:
.csproj file you want to add the Volo.Abp.EventBus.Azure package.abp add-package Volo.Abp.EventBus.Azure command.If you want to do it manually, install the Volo.Abp.EventBus.Azure NuGet package to your project and add [DependsOn(typeof(AbpEventBusAzureModule))] to the ABP module class inside your project.
You can configure using the standard configuration system, like using the appsettings.json file, or using the options classes.
appsettings.json file configurationThis is the simplest way to configure the Azure Service Bus settings. It is also very strong since you can use any other configuration source (like environment variables) that is supported by the AspNet Core.
Example: The minimal configuration to connect to Azure Service Bus Namespace with default configurations
{
"Azure": {
"ServiceBus": {
"Connections": {
"Default": {
"ConnectionString": "Endpoint=sb://sb-my-app.servicebus.windows.net/;SharedAccessKeyName={%{{{Policy Name}}}%};SharedAccessKey={};EntityPath=marketing-consent"
}
}
},
"EventBus": {
"ConnectionName": "Default",
"SubscriberName": "MySubscriberName",
"TopicName": "MyTopicName"
}
}
}
MySubscriberName is the name of this subscription, which is used as the Subscriber on the Azure Service Bus.MyTopicName is the topic name.See the Azure Service Bus document to understand these options better.
If you need to connect to another Azure Service Bus Namespace the Default, you need to configure the connection properties.
Example: Declare two connections and use one of them for the event bus
{
"Azure": {
"ServiceBus": {
"Connections": {
"Default": {
"ConnectionString": "Endpoint=sb://sb-my-app.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey={%{{{SharedAccessKey}}}%}"
},
"SecondConnection": {
"ConnectionString": "Endpoint=sb://sb-my-app.servicebus.windows.net/;SharedAccessKeyName={%{{{Policy Name}}}%};SharedAccessKey={%{{{SharedAccessKey}}}%}"
}
}
},
"EventBus": {
"ConnectionName": "SecondConnection",
"SubscriberName": "MySubscriberName",
"TopicName": "MyTopicName"
}
}
}
This allows you to use multiple Azure Service Bus namespaces in your application, but select one of them for the event bus.
You can use any of the ServiceBusAdministrationClientOptions, ServiceBusClientOptions, ServiceBusProcessorOptions properties for the connection.
Example: Specify the Admin, Client and Processor options
{
"Azure": {
"ServiceBus": {
"Connections": {
"Default": {
"ConnectionString": "Endpoint=sb://sb-my-app.servicebus.windows.net/;SharedAccessKeyName={%{{{Policy Name}}}%};SharedAccessKey={};EntityPath=marketing-consent",
"Admin": {
"Retry": {
"MaxRetries": 3
}
},
"Client": {
"RetryOptions": {
"MaxRetries": 1
}
},
"Processor": {
"AutoCompleteMessages": true,
"ReceiveMode": "ReceiveAndDelete"
}
}
}
},
"EventBus": {
"ConnectionName": "Default",
"SubscriberName": "MySubscriberName",
"TopicName": "MyTopicName"
}
}
}
AbpAzureServiceBusOptions and AbpAzureEventBusOptions classes can be used to configure the connection strings and event bus options for Azure Service Bus.
You can configure this options inside the ConfigureServices of your module.
Example: Configure the connection
Configure<AbpAzureServiceBusOptions>(options =>
{
options.Connections.Default.ConnectionString = "Endpoint=sb://sb-my-app.servicebus.windows.net/;SharedAccessKeyName={%{{{Policy Name}}}%};SharedAccessKey={}";
options.Connections.Default.Admin.Retry.MaxRetries = 3;
options.Connections.Default.Client.RetryOptions.MaxRetries = 1;
});
Use TokenCredential instead of ConnectionString if you want to use custom credential.
Configure<AbpAzureServiceBusOptions>(options =>
{
options.Connections.Default.FullyQualifiedNamespace = "sb-my-app.servicebus.windows.net";
options.Connections.Default.TokenCredential = new DefaultAzureCredential();
});
Using these options classes can be combined with the appsettings.json way. Configuring an option property in the code overrides the value in the configuration file.