Starts in:
3 DAYS
9 HRS
22 MIN
15 SEC
Starts in:
3 D
9 H
22 M
15 S

Distributed Event Bus Azure Integration

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

Installation

Use the ABP CLI to add Volo.Abp.EventBus.Azure NuGet package to your project:

  • Install the ABP CLI if you haven't installed before.
  • Open a command line (terminal) in the directory of the .csproj file you want to add the Volo.Abp.EventBus.Azure package.
  • Run 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.

Configuration

You can configure using the standard configuration system, like using the appsettings.json file, or using the options classes.

appsettings.json file configuration

This 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.

Connections

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"
    }
  }
}

The Options Classes

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;
});

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.

Contributors


Last updated: July 31, 2024 Edit this page on GitHub

Was this page helpful?

Please make a selection.

To help us improve, please share your reason for the negative feedback in the field below.

Please enter a note.

Thank you for your valuable feedback!

Please note that although we cannot respond to feedback, our team will use your comments to improve the experience.

In this document
Community Talks

What’s New with .NET 9 & ABP 9?

21 Nov, 17:00
Online
Register Now
Mastering ABP Framework Book
Mastering ABP Framework

This book will help you gain a complete understanding of the framework and modern web application development techniques.

Learn More