PubSubClient.RabbitMQ 1.0.3

dotnet add package PubSubClient.RabbitMQ --version 1.0.3                
NuGet\Install-Package PubSubClient.RabbitMQ -Version 1.0.3                
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="PubSubClient.RabbitMQ" Version="1.0.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PubSubClient.RabbitMQ --version 1.0.3                
#r "nuget: PubSubClient.RabbitMQ, 1.0.3"                
#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 PubSubClient.RabbitMQ as a Cake Addin
#addin nuget:?package=PubSubClient.RabbitMQ&version=1.0.3

// Install PubSubClient.RabbitMQ as a Cake Tool
#tool nuget:?package=PubSubClient.RabbitMQ&version=1.0.3                

PubSubClient

PubSubClient is a flexible and powerful publish-subscribe (pub/sub) messaging library designed for .NET applications. It enables easy integration of event-driven architectures with a variety of message brokers, allowing you to publish and subscribe to messages in a decoupled manner.

Features

  • Broker-Agnostic: Supports multiple message brokers such as RabbitMQ, Kafka, and others.
  • Easy Integration: Designed to work seamlessly with ASP.NET Core and other .NET applications.
  • Asynchronous Processing: Built-in support for asynchronous message processing.
  • Scalability: Suitable for high-throughput, distributed environments.

Installation

To install PubSubClient in your project, you can use the following NuGet command for your provider:

dotnet add package PubSubClient.ActiveMQ
dotnet add package PubSubClient.Kafka
dotnet add package PubSubClient.RabbitMQ

Usage

Basic Setup

  1. Configuration

    PubSubClient expects the configuration for the broker connection in the MessageBroker section of the config. Example configurations provided below for each provider and links to documentation.

  2. Register PubSubClient with the desired broker in your DI Container:

    using PubSubClient;
    using PubSubClient.RabbitMQ
    
     public class Startup
     {
         public void ConfigureServices(IServiceCollection services)
         {
             services.AddPubSubClient<RabbitMqConsumerService, RabbitMqPublisherService>(); // Example using RabbitMQ
         }
     }
    
  3. Define a Service Definition:

    using PubSubClient;
    
    public class MyServiceDefinition : MicroServiceDefinitionBase
    {
    	public override string ExchangeName => "MyExchange";
    }
    
  4. Publish a message:

     public class MyPublisherService
     {
         private readonly IPublisherService _publisher;
    
         public MyPublisherService(IPublisherService publisher)
         {
             _publisher = publisher;
         }
    
         public async Task PublishMessageAsync()
         {
             var message = new MyMessage { MessageContent = "Hello, PubSub!" };
             await _publisher.PublishAsync(message, new MyServiceDefinition());
         }
     }
    
  5. Consume messages:

    using PubSubClient.Attributes;
    
    public class Consumers
    {
         [ConsumerMethod(typeof(MyServiceDefinition))]
         public async Task RunMyMethod(object o, MyMessage message)
         {
             await Task.FromResult(0);
             Console.WriteLine($"Received message: {message.MessageContent}");
         }
     }
    

    Note: The consumer method must a signature of (object, T) or (T). The object passed is the entire message with metadata from the broker.

Supported Message Brokers

PubSubClient supports multiple brokers. Each broker can be installed as a separate NuGet package:

  • RabbitMQ: A popular message broker for reliable messaging.

    "MessageBroker": {
        "HostName": "localhost:5672",
        "DispatchConsumersAsync": true
      }
    

    See here for documentation.

  • Kafka: High-throughput, distributed streaming platform.

      "MessageBroker": {
        "BootstrapServers": "localhost:9092",
        "saslUsername": "admin",
        "saslPassword": "admin123",
        "SecurityProtocol": 2,
        "SaslMechanism": 1,
        "AutoOffsetReset": 1
      }
    

    See here for documentation.

  • Apache ActiveMQ: Open-source, multi-protocol distributed messaging platform.

      "MessageBroker": {
        "MqServerName": "activemq:tcp://localhost:61616",
        "MqUserName": "artemis",
        "MqPassword": "artemis",
      }
    

    Note: These are the only configuration options available for ActiveMQ

Adding Custom Brokers

You can also implement your own custom consumer and publisher by creating a class that implements the IConsumerService and IPublisherService interfaces.

public class MyCustomConsumerService : IConsumerService
{
    // Implementation goes here
}

public class MyCustomPublisherService : IPublisherService
{
    // Implementation goes here
}

License

PubSubClient is licensed under the GPL License. See the LICENSE for more information.

Contributing

Contributions are always welcome! Feel free to open an issue or submit a pull request.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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
1.0.3 88 10/3/2024
1.0.2 89 9/23/2024
1.0.1 90 9/22/2024
1.0.0 87 9/22/2024