DotNetBrightener.Plugins.EventPubSub.AzureServiceBus
                               
                            
                                2025.0.9-preview-535
                            
                        
                    See the version list below for details.
dotnet add package DotNetBrightener.Plugins.EventPubSub.AzureServiceBus --version 2025.0.9-preview-535
NuGet\Install-Package DotNetBrightener.Plugins.EventPubSub.AzureServiceBus -Version 2025.0.9-preview-535
<PackageReference Include="DotNetBrightener.Plugins.EventPubSub.AzureServiceBus" Version="2025.0.9-preview-535" />
<PackageVersion Include="DotNetBrightener.Plugins.EventPubSub.AzureServiceBus" Version="2025.0.9-preview-535" />
<PackageReference Include="DotNetBrightener.Plugins.EventPubSub.AzureServiceBus" />
paket add DotNetBrightener.Plugins.EventPubSub.AzureServiceBus --version 2025.0.9-preview-535
#r "nuget: DotNetBrightener.Plugins.EventPubSub.AzureServiceBus, 2025.0.9-preview-535"
#:package DotNetBrightener.Plugins.EventPubSub.AzureServiceBus@2025.0.9-preview-535
#addin nuget:?package=DotNetBrightener.Plugins.EventPubSub.AzureServiceBus&version=2025.0.9-preview-535&prerelease
#tool nuget:?package=DotNetBrightener.Plugins.EventPubSub.AzureServiceBus&version=2025.0.9-preview-535&prerelease
Azure Service Bus Enabled for Event PubSub Library
© 2025 DotNet Brightener
Versions
| Library | Version | 
|---|---|
| EventPubSub Core | |
| Azure Service Bus Library | |
| Dependency Injection Library | 
Installation
dotnet package add DotNetBrightener.Plugins.EventPubSub
dotnet package add DotNetBrightener.Plugins.EventPubSub.DependencyInjection
dotnet package add DotNetBrightener.Plugins.EventPubSub.AzureServiceBus
Usage
Configuration
Option 1: Use IConfiguration to configure the service bus
builder.Services
        // Initialize EventPubSubService
       .AddEventPubSubService(
                              Assembly.GetExecutingAssembly(),
                              // assemblies where the event messages are defined
                              typeof(DistributedTestMessage).Assembly
                             )
        // Add Azure Service Bus
       .AddAzureServiceBus(builder.Configuration)
        // Add event handlers
       .AddEventHandlersFromAssemblies([
            Assembly.GetExecutingAssembly(),
            // assemblies where the event handlers are defined
        ]);
In your appsettings.json file, add the the following configuration:
"ServiceBusConfiguration": {
    "ConnectionString": "<connection_string_to_Azure_Service_Bus",
    "SubscriptionName": "<your_app_name>"
} 
Option 2: Configure from code
builder.Services
        // Initialize EventPubSubService
       .AddEventPubSubService(
                              Assembly.GetExecutingAssembly(),
                              // assemblies where the event messages are defined
                              typeof(DistributedTestMessage).Assembly
                             )
        // Add Azure Service Bus
       .AddAzureServiceBus("<connection_string_to_Azure_Service_Bus>",
                           "<your_app_name>")
        // Add event handlers
       .AddEventHandlersFromAssemblies([
            Assembly.GetExecutingAssembly(),
            // assemblies where the event handlers are defined
        ]);
Default Configuration Value
If you use appsettings.json to configure the service bus, you can also customize the following configuration values by adding it to the JSON:
| Configuration | Description | Value Type | Default Value | 
|---|---|---|---|
| ConnectionString | The connection string to Azure Service Bus | string | required, must specify | 
| SubscriptionName | The name of the application that subscribes to the events from Azure Service Bus | string | required, must specify | 
| IncludeNamespaceForTopicName | Indicates if the namespace of the class is used for topic name | boolean | true, means the namespace will be used for topic name.<br />Set tofalseto only use class name as topic name | 
| AutoDeleteOnIdle | The TimeSpanidle interval after which the topic is automatically deleted. | TimeSpan | TimeSpan.FromDays(90), means the topic will be automatically deleted after 90 days. | 
| DefaultMessageTimeToLive | The default time to live value for the messages. This is the duration after which the message expires, starting from when the message is sent to Service Bus. | TimeSpan | TimeSpan.FromDays(5) | 
| DuplicateDetectionHistoryTimeWindow | The TimeSpanduration of duplicate detection history that is maintained by the service. | TimeSpan | TimeSpan.FromMinutes(1) | 
| MaxSizeInMegabytes | The maximum size of the topic in megabytes, which is the size of memory allocated for the topic. | long | 5120 | 
Event Message Definition
Create a class that represents the event message. The class must implement the IDistributedEventMessage interface.
namespace YourProject.NameSpace;
public class DistributedTestMessage : IDistributedEventMessage
{
    public string Name { get; set; }
    // more payload properties
}
Event Handler Definition
Create a class derived from DistributedEventEventHandler<YourEventMessage> and override HandleEvent method to handle the event message.
With this implementation, you'll be able to access the original payload of the messsage by accessing OriginPayload property.
public class TestEventHandlerDistributed(ILogger<TestEventHandlerDistributed> logger)
    : DistributedEventEventHandler<DistributedTestMessage>
{
    private readonly ILogger _logger = logger;
    
    public override Task<bool> HandleEvent(DistributedTestMessage eventMessage)
    {
        // access the `OriginPayload` 
        var origin = OriginPayload;
        _logger.LogInformation($"Received message: {eventMessage.Name}");
        return Task.FromResult<bool>(true);
    }
}
| Product | Versions Compatible and additional computed target framework versions. | 
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. | 
- 
                                                    net9.0- Azure.Messaging.ServiceBus (>= 7.20.1)
- DotNetBrightener.Plugins.EventPubSub (>= 2025.0.9-preview-535)
- DotNetBrightener.Plugins.EventPubSub.Distributed (>= 2025.0.9-preview-535)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.9)
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.9)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.9)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 9.0.9)
 
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.