DotNetBrightener.Plugins.EventPubSub.AzureServiceBus 2024.0.14-preview-1

This is a prerelease version of DotNetBrightener.Plugins.EventPubSub.AzureServiceBus.
There is a newer version of this package available.
See the version list below for details.
dotnet add package DotNetBrightener.Plugins.EventPubSub.AzureServiceBus --version 2024.0.14-preview-1                
NuGet\Install-Package DotNetBrightener.Plugins.EventPubSub.AzureServiceBus -Version 2024.0.14-preview-1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DotNetBrightener.Plugins.EventPubSub.AzureServiceBus" Version="2024.0.14-preview-1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DotNetBrightener.Plugins.EventPubSub.AzureServiceBus --version 2024.0.14-preview-1                
#r "nuget: DotNetBrightener.Plugins.EventPubSub.AzureServiceBus, 2024.0.14-preview-1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DotNetBrightener.Plugins.EventPubSub.AzureServiceBus as a Cake Addin
#addin nuget:?package=DotNetBrightener.Plugins.EventPubSub.AzureServiceBus&version=2024.0.14-preview-1&prerelease

// Install DotNetBrightener.Plugins.EventPubSub.AzureServiceBus as a Cake Tool
#tool nuget:?package=DotNetBrightener.Plugins.EventPubSub.AzureServiceBus&version=2024.0.14-preview-1&prerelease                

Azure Service Bus Enabled for Event PubSub Library

© 2024 DotNet Brightener

Versions

Library Version
EventPubSub Core NuGet Version
Azure Service Bus Library NuGet Version
Dependency Injection Library NuGet Version

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 to false to only use class name as topic name
AutoDeleteOnIdle The TimeSpan idle 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 TimeSpan duration 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 Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2024.0.14.6-rc-242771401 63 10/3/2024
2024.0.14.6-rc-242770501 33 10/3/2024
2024.0.14.6-rc-242770201 42 10/3/2024
2024.0.14.6-rc-242761801 33 10/2/2024
2024.0.14.6-rc-242761601 47 10/2/2024
2024.0.14.6-rc-242761501 33 10/2/2024
2024.0.14.6-rc-242761401 46 10/2/2024
2024.0.14.6-rc-242760701 51 10/2/2024
2024.0.14.6-rc-242751002 50 10/1/2024
2024.0.14.6-rc-242750901 64 10/1/2024
2024.0.14.6-rc-242750502 62 10/1/2024
2024.0.14.6-rc-242750201 71 10/1/2024
2024.0.14.6-rc-242741501 64 9/30/2024
2024.0.14.6-rc-242730701 93 9/29/2024
2024.0.14.6-preview-2730501 57 9/29/2024
2024.0.14.6-preview-2701501 96 9/26/2024
2024.0.14.6-preview-2620901 111 9/18/2024
2024.0.14.6-preview-2570701 83 9/13/2024
2024.0.14.6-preview-2510703 127 9/7/2024
2024.0.14.6-preview-2480501 85 9/4/2024
2024.0.14.6-preview-2430401 100 8/30/2024
2024.0.14.6-preview-242730701 59 9/29/2024
2024.0.14.6-preview-2421703 73 8/29/2024
2024.0.14.6-preview-2421701 70 8/29/2024
2024.0.14.6-preview-2420901 70 8/29/2024
2024.0.14.6-preview-2390101 79 8/26/2024
2024.0.14.6-preview-2381603 96 8/25/2024
2024.0.14.6-preview-2341601 114 8/21/2024
2024.0.14.6-preview-2321602 98 8/20/2024
2024.0.14.6-preview-2190801 103 8/6/2024
2024.0.14.6-preview-2041501 83 7/22/2024
2024.0.14.6-preview-1920603 142 7/10/2024
2024.0.14.6-preview-1920301 77 7/10/2024
2024.0.14.6-preview-1911302 90 7/9/2024
2024.0.14.6-preview-1901001 102 7/8/2024
2024.0.14.6-preview-1900901 87 7/8/2024
2024.0.14.6-preview-1900801 80 7/8/2024
2024.0.14.6-preview-1860304 86 7/4/2024
2024.0.14.5 139 7/1/2024
2024.0.14.5-preview-1811601 83 6/29/2024
2024.0.14.5-preview-1810501 101 6/29/2024
2024.0.14.5-preview-180132 88 6/28/2024
2024.0.14.5-preview-180131 89 6/28/2024
2024.0.14.5-preview-180121 72 6/28/2024
2024.0.14.4 97 6/27/2024
2024.0.14.4-preview-7 80 6/27/2024
2024.0.14.3 91 6/21/2024
2024.0.14.1 97 6/6/2024
2024.0.14.1-preview 73 6/6/2024
2024.0.14-preview-1 83 6/6/2024
2024.0.13.8-preview 102 6/6/2024
2024.0.13.1-preview-0146 101 6/6/2024
2024.0.12.15803-preview-03 87 6/6/2024
2024.0.12.15608 95 6/4/2024
2024.0.12.15515 175 6/3/2024
2024.0.12.15220 86 5/31/2024
2024.0.12.15220-alpha31-240... 80 5/31/2024
2024.0.12.14911 135 5/28/2024
2024.0.12.14910-alpha28-240... 87 5/28/2024
2024.0.12.14823 124 5/27/2024
2024.0.12.14522-alpha7-2405... 100 5/24/2024
2024.0.12.14514-alpha6-2405... 92 5/24/2024
2024.0.12.14511 113 5/24/2024
2024.0.12.14314 148 5/22/2024
2024.0.12.14114 145 5/20/2024