DotNetBrightener.Plugins.EventPubSub.Distributed 2025.0.4-preview-292

This is a prerelease version of DotNetBrightener.Plugins.EventPubSub.Distributed.
There is a newer version of this package available.
See the version list below for details.
dotnet add package DotNetBrightener.Plugins.EventPubSub.Distributed --version 2025.0.4-preview-292
                    
NuGet\Install-Package DotNetBrightener.Plugins.EventPubSub.Distributed -Version 2025.0.4-preview-292
                    
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.Distributed" Version="2025.0.4-preview-292" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DotNetBrightener.Plugins.EventPubSub.Distributed" Version="2025.0.4-preview-292" />
                    
Directory.Packages.props
<PackageReference Include="DotNetBrightener.Plugins.EventPubSub.Distributed" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DotNetBrightener.Plugins.EventPubSub.Distributed --version 2025.0.4-preview-292
                    
#r "nuget: DotNetBrightener.Plugins.EventPubSub.Distributed, 2025.0.4-preview-292"
                    
#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.
#:package DotNetBrightener.Plugins.EventPubSub.Distributed@2025.0.4-preview-292
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DotNetBrightener.Plugins.EventPubSub.Distributed&version=2025.0.4-preview-292&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=DotNetBrightener.Plugins.EventPubSub.Distributed&version=2025.0.4-preview-292&prerelease
                    
Install as a Cake Tool

Distributed Integration for Event PubSub Library

© 2024 DotNet Brightener

Versions

Library Version
EventPubSub Core NuGet Version
EventPubSub Distributed Library NuGet Version
Dependency Injection Library NuGet Version
Azure Service Bus Integration Library NuGet Version
RabbitMq Integration Library NuGet Version

Installation

dotnet package add DotNetBrightener.Plugins.EventPubSub
dotnet package add DotNetBrightener.Plugins.EventPubSub.DependencyInjection
dotnet package add DotNetBrightener.Plugins.EventPubSub.Distributed
dotnet package add DotNetBrightener.Plugins.EventPubSub.AzureServiceBus
# or 
dotnet add package DotNetBrightener.Plugins.EventPubSub.RabbitMq

Usage

Configuration

Option 1: Use IConfiguration to configure the service bus

// Initialize EventPubSubService
var eventPubSubConfig = builder.Services
                               .AddEventPubSubService()
                                // scan for event messages in the given assembly
                               .AddEventMessagesFromAssemblies(typeof(DistributedTestMessage).Assembly)
                                // scan for event handlers in the given assembly
                               .AddEventHandlersFromAssemblies(Assembly.GetExecutingAssembly());

// Add Azure Service Bus
//eventPubSubConfig.UseAzureServiceBus(builder.Configuration)
//                 .Finalize();

// Add RabbitMq
eventPubSubConfig.UseRabbitMq(builder.Configuration)
                 .Finalize();

In your appsettings.json file, add the the following configuration:

  "ServiceBusConfiguration": {
    "ConnectionString": "<your-endpoint-to-azure-service-bus>",
    "SubscriptionName": "<application-name>",
    "IncludeNamespaceForTopicName": false
  },
  "RabbitMqConfiguration": {
    "Host": "<rabbit-mq-host>",
    "Username": "<rabbit-mq-username>",
    "Password": "<rabbit-mq-password>",
    "VirtualHost": "<rabbit-mq-virtual-host>",
    "SubscriptionName": "<application-name>",
    "IncludeNamespaceForTopicName": false
  }
Option 2: Configure from code

// Initialize EventPubSubService
var eventPubSubConfig = builder.Services
                               .AddEventPubSubService()
                                // scan for event messages in the given assembly
                               .AddEventMessagesFromAssemblies(Assembly.GetExecutingAssembly(), typeof(DistributedTestMessage).Assembly)
                                // scan for event handlers in the given assembly
                               .AddEventHandlersFromAssemblies(Assembly.GetExecutingAssembly());

var distributedIntegrations = eventPubSubConfig.EnableDistributedIntegrations();

distributedIntegrations.SetSubscriptionName("<application-name>");
// if you want to exclude namespace in entity name
distributedIntegrations.ExcludeNamespaceInEntityName();

// Add Azure Service Bus
distributedIntegrations.UseAzureServiceBus("<azure-connection-string>");

// Or Add RabbitMq - Note that only one or the other can be used
/*
distributedIntegrations.UseRabbitMq("<rabbit-mq-host>",
                                    "<rabbit-mq-username>",
                                    "<rabbit-mq-password>",
                                    "<rabbit-mq-virtual-host>");
*/

// this should be called before builder.Build(), or before exiting ConfigureServices method
distributedIntegrations.Finalize();

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

Request - Response Message Pattern

Create 2 (two) classes that represents the request message and the response message. The request message class must implement the IRequestMessage interface, while the response message class must implement the IResponseMessage<T> interface, where T is the request message type.


namespace YourProject.NameSpace;

public class RequestMessage : IRequestMessage
{
    public string Name { get; set; }

    // more payload properties
}

public class ResponseMessage : IResponseMessage<RequestMessage>
{
    public string Name { get; set; }

    // more payload properties
}

When you want to initiate a request to obtain the needed response, use IEventPublisher to initiate it as follow:


var requestMessage = new RequestMessage
{
    Name = eventMessage.Name
};

var response = await eventPublisher.GetResponse<ResponseMessage, RequestMessage>(requestMessage);

Request - Response Handler Definition

Create a class derived from RequestResponder<YourRequestMessage> and override HandleEvent method to handle the event message.



public class HandleRequestMessage(ILogger<HandleRequestMessage> logger)
    : RequestResponder<RequestMessage>
{    
    public override async Task<bool> HandleEvent(RequestMessage eventMessage)
    {
        // do something with the request message, e.g. logging it
        logger.LogInformation($"Received message: {eventMessage.Name}");

        // create a response message - this response message must implement IResponseMessage<T> interface
        var responseMessage = new ResponseMessage
        {
            Name = eventMessage.Name
        };

        // send the response message
        await SendResponse(responseMessage);

        return Task.FromResult<bool>(true);
    }
}

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on DotNetBrightener.Plugins.EventPubSub.Distributed:

Package Downloads
DotNetBrightener.Plugins.EventPubSub.AzureServiceBus

Package Description

DotNetBrightener.Plugins.EventPubSub.RabbitMq

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2026.0.1-preview-notificati... 104 12/6/2025
2026.0.1-preview-net10-upgr... 186 11/25/2025
2026.0.1-preview-net10-upgr... 186 11/25/2025
2026.0.1-preview-net10-upgr... 176 11/24/2025
2026.0.1-preview-net10-upgr... 200 11/24/2025
2026.0.1-preview-713 440 12/10/2025
2026.0.1-preview-700 216 12/7/2025
2026.0.1-preview-689 119 12/6/2025
2026.0.1-preview-676 677 12/2/2025
2026.0.1-preview-671 128 11/29/2025
2026.0.1-preview-670 119 11/29/2025
2026.0.1-preview-669 115 11/29/2025
2026.0.1-preview-667 185 11/27/2025
2026.0.1-preview-665 176 11/27/2025
2026.0.1-preview-664 171 11/27/2025
2026.0.1-preview-660 179 11/25/2025
2025.0.10 197 11/25/2025
2025.0.10-preview-628 406 11/20/2025
2025.0.10-preview-605 275 11/17/2025
2025.0.10-preview-602 284 11/17/2025
2025.0.10-preview-581 298 11/11/2025
2025.0.10-preview-559 193 10/29/2025
2025.0.10-preview-557 190 10/27/2025
2025.0.9 185 10/26/2025
2025.0.9-preview-553 181 10/26/2025
2025.0.9-preview-539 123 10/12/2025
2025.0.9-preview-535 180 10/8/2025
2025.0.9-preview-509 188 10/2/2025
2025.0.9-preview-508 171 10/2/2025
2025.0.9-preview-487 189 9/29/2025
2025.0.9-preview-481 181 9/29/2025
2025.0.9-preview-473 167 9/28/2025
2025.0.8 205 9/23/2025
2025.0.6 202 9/22/2025
2025.0.6-preview-455 199 9/22/2025
2025.0.6-preview-454 314 9/17/2025
2025.0.6-preview-441 161 9/14/2025
2025.0.6-preview-440 156 9/14/2025
2025.0.6-preview-406 189 9/2/2025
2025.0.6-preview-401 180 9/2/2025
2025.0.6-preview-400 181 9/2/2025
2025.0.6-preview-369 224 8/27/2025
2025.0.6-preview-368 223 8/27/2025
2025.0.6-preview-334 195 8/18/2025
2025.0.6-preview-333 180 7/27/2025
2025.0.6-preview-332 512 7/24/2025
2025.0.6-preview-331 518 7/24/2025
2025.0.6-preview-328 515 7/24/2025
2025.0.6-preview-327 368 7/21/2025
2025.0.6-preview-326 365 7/21/2025
2025.0.6-preview-325 278 7/20/2025
2025.0.6-preview-324 272 7/20/2025
2025.0.6-preview-322 268 7/20/2025
2025.0.6-preview-321 274 7/19/2025
2025.0.6-preview-320 275 7/19/2025
2025.0.6-preview-319 177 7/17/2025
2025.0.6-preview-317 177 7/17/2025
2025.0.6-preview-316 177 7/17/2025
2025.0.6-preview-315 179 7/17/2025
2025.0.6-preview-314 177 7/17/2025
2025.0.6-preview-313 181 7/17/2025
2025.0.6-preview-312 175 7/16/2025
2025.0.5 193 7/10/2025
2025.0.5-preview-307 116 7/5/2025
2025.0.4 127 7/5/2025
2025.0.4-preview-305 134 7/4/2025
2025.0.4-preview-304 188 7/1/2025
2025.0.4-preview-299 164 5/31/2025
2025.0.4-preview-298 140 5/30/2025
2025.0.4-preview-296 184 5/30/2025
2025.0.4-preview-295 187 5/29/2025
2025.0.4-preview-293 186 5/26/2025
2025.0.4-preview-292 200 5/26/2025
2025.0.3 183 2/10/2025
2025.0.3-preview-288 162 2/10/2025
2025.0.2 175 1/21/2025
2025.0.2-preview-278 154 1/21/2025
2025.0.2-preview-277 169 12/16/2024
2025.0.1-rc-243301701 441 11/25/2024
2024.0.14.6 179 11/25/2024
2024.0.14.6-rc-243031001 248 10/29/2024
2024.0.14.6-rc-243030701 172 10/29/2024
2024.0.14.6-rc-242840501 166 10/10/2024
2024.0.14.6-rc-242820305 165 10/8/2024
2024.0.14.6-rc-242771401 266 10/3/2024
2024.0.14.6-rc-242770501 170 10/3/2024
2024.0.14.6-rc-242770201 185 10/3/2024
2024.0.14.6-rc-242761801 181 10/2/2024
2024.0.14.6-rc-242761601 187 10/2/2024
2024.0.14.6-rc-242761501 177 10/2/2024
2024.0.14.6-rc-242761401 174 10/2/2024
2024.0.14.6-rc-242760701 188 10/2/2024
2024.0.14.6-rc-242751002 170 10/1/2024
2024.0.14.6-rc-242750901 190 10/1/2024
2024.0.14.6-rc-242750502 176 10/1/2024
2024.0.14.6-rc-242750201 180 10/1/2024
2024.0.14.6-rc-242741501 162 9/30/2024
2024.0.14.6-rc-242730701 193 9/29/2024
2024.0.14.6-preview-2730501 156 9/29/2024
2024.0.14.6-preview-2701501 198 9/26/2024
2024.0.14.6-preview-2620901 209 9/18/2024
2024.0.14.6-preview-2570701 181 9/13/2024
2024.0.14.6-preview-2510703 231 9/7/2024
2024.0.14.6-preview-2480501 177 9/4/2024
2024.0.14.6-preview-2430401 201 8/30/2024
2024.0.14.6-preview-242730701 161 9/29/2024
2024.0.14.6-preview-2421703 171 8/29/2024
2024.0.14.6-preview-2421701 169 8/29/2024
2024.0.14.6-preview-2420901 164 8/29/2024