NanoRabbit 0.2.3
dotnet add package NanoRabbit --version 0.2.3
NuGet\Install-Package NanoRabbit -Version 0.2.3
<PackageReference Include="NanoRabbit" Version="0.2.3" />
<PackageVersion Include="NanoRabbit" Version="0.2.3" />
<PackageReference Include="NanoRabbit" />
paket add NanoRabbit --version 0.2.3
#r "nuget: NanoRabbit, 0.2.3"
#addin nuget:?package=NanoRabbit&version=0.2.3
#tool nuget:?package=NanoRabbit&version=0.2.3
About
NanoRabbit, A Lightweight RabbitMQ .NET 3rd party library for .NET 6 and up, which makes a simple way to manage Multiple connections, producers, consumers, and easy to use.
Building
Branch | Building Status |
---|---|
master | |
dev |
Features
- Customize the name of producers, consumers.
- Dependency injection available.
- Multiple connections, producers, and consumers can be created.
Installation
You can get NanoRabbit by grabbing the latest NuGet package.
See Wiki for more details.
Version
NanoRabbit | RabbitMQ.Client | .NET |
---|---|---|
0.0.1 ~ 0.1.8 | obsolete | obsolete |
0.1.9 ~ 0.2.3 | 6.5.0-6.8.1 | 6.0, 7.0, 8.0 |
Document
For details, see: NanoRabbit Wiki.
QuickStart
NanoRabbit is designed as a library depends on NAMING Connections, Producers and Consumers. So it's important to set a UNIQUE NAME for each Connections, Producers and Consumers.
For more, please visit the Examples.
Setup RabbitProducers && RabbitConsumers
RabbitProducer
Register a RabbitMQ Producer by calling RabbitHelper(RabbitConfiguration rabbitConfig, ILogger<RabbitHelper>? logger = null)
, and configure it.
using NanoRabbit;
using NanoRabbit.Connection;
var loggerFactory = LoggerFactory.Create(builder =>
{
builder.AddConsole();
});
var logger = loggerFactory.CreateLogger("RabbitHelper");
var rabbitHelper = new RabbitHelper(rabbitConfig: new RabbitConfiguration
{
HostName = "localhost",
Port = 5672,
VirtualHost = "/",
UserName = "admin",
Password = "admin",
Producers = new List<ProducerOptions> { new ProducerOptions {
ProducerName = "FooProducer",
ExchangeName = "amq.topic",
RoutingKey = "foo.key",
Type = ExchangeType.Topic
}
}
}, logger);
RabbitConsumer
Register a RabbitMQ Consumer by calling RabbitHelper()
, and configure it.
using NanoRabbit;
using NanoRabbit.Connection;
var rabbitHelper = new RabbitHelper(rabbitConfig: new RabbitConfiguration
{
HostName = "localhost",
Port = 5672,
VirtualHost = "/",
UserName = "admin",
Password = "admin",
Consumers = new List<ConsumerOptions> { new ConsumerOptions {
ConsumerName= "FooConsumer",
QueueName = "foo-queue"
}
}
}, logger);
Simple Publish Messages
After registering a RabbitProducer
in the RabbitHelper
, you can simply publish a message by calling Publish<T>(string producerName, T message)
.
rabbitHelper.Publish<string>("FooProducer", "Hello from NanoRabbit");
Asynchronously publishing is also available:
await rabbitHelper.PublishAsync<string>("FooProducer", "Hello from NanoRabbit");
Simple Consume Messages
After registering a RabbitConsumer
in the RabbitConsumer
, you can simply consume a message by
calling AddConsumer(string consumerName, Action<string> onMessageReceived, int consumers = 1)
.
while (true)
{
rabbitHelper.AddConsumer("FooConsumer", message =>
{
Console.WriteLine(message);
});
}
Forward messages
Working on it.
DependencyInjection
NanoRabbit provides some functions to inject IRabbitHelper in a simple way.
AddRabbitProducer
var builder = Host.CreateApplicationBuilder(args);
// Configure the RabbitMQ Connection
builder.Services.AddRabbitHelper(builder =>
{
builder.SetHostName("localhost")
.SetPort(5672)
.SetVirtualHost("/")
.SetUserName("admin")
.SetPassword("admin")
.AddProducerOption(producer =>
{
producer.ProducerName = "FooProducer";
producer.ExchangeName = "amq.topic";
producer.RoutingKey = "foo.key";
producer.Type = ExchangeType.Topic;
});
});
using IHost host = builder.Build();
host.Run();
AddRabbitConsumer
var builder = Host.CreateApplicationBuilder(args);
// Configure the RabbitMQ Connection
builder.Services.AddRabbitHelper(builder =>
{
builder.SetHostName("localhost")
.SetPort(5672)
.SetVirtualHost("/")
.SetUserName("admin")
.SetPassword("admin")
.AddConsumerOption(consumer =>
{
consumer.ConsumerName = "FooConsumer";
consumer.QueueName = "foo-queue";
})
.AddConsumerOption(consumer =>
{
consumer.ConsumerName = "BarConsumer";
consumer.QueueName = "bar-queue";
});
})
.AddRabbitConsumer<FooQueueHandler>("FooConsumer", consumers: 3)
.AddRabbitConsumer<BarQueueHandler>("BarConsumer", consumers: 2);
using IHost host = builder.Build();
host.Run();
More Dependency Injection Usage at Wiki.
Contributing
- Fork this repository.
- Create a new branch in you current repos from the dev branch.
- Push commits and create a Pull Request (PR) to NanoRabbit.
Todo
- Basic Consume & Publish
- DependencyInjection
- Logging
- Support .NET latest frameworks
- Forward messages
- ASP.NET support
- TLS support
- Re-trying of failed sends
- Basic RabbitMQ.Client functions extensions
Thanks
- Visual Studio 2022
- RabbitMQ.Client
- Newtonsoft.Json
- Masstransit
- EasyNetQ
- Polly.Core
License
NanoRabbit is licensed under the MIT license.
Product | Versions 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 is compatible. 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. net9.0 was computed. 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. |
-
net6.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Logging (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Logging.Console (>= 8.0.0)
- Newtonsoft.Json (>= 13.0.3)
- Polly.Core (>= 8.4.1)
- RabbitMQ.Client (>= 6.5.0)
-
net7.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Logging (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Logging.Console (>= 8.0.0)
- Newtonsoft.Json (>= 13.0.3)
- Polly.Core (>= 8.4.1)
- RabbitMQ.Client (>= 6.5.0)
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Logging (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Logging.Console (>= 8.0.0)
- Newtonsoft.Json (>= 13.0.3)
- Polly.Core (>= 8.4.1)
- RabbitMQ.Client (>= 6.5.0)
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 |
---|---|---|
0.2.3 | 166 | 12/23/2024 |
0.2.2 | 264 | 9/10/2024 |
0.2.1 | 164 | 9/4/2024 |
0.2.0 | 152 | 8/2/2024 |
0.1.9 | 108 | 7/11/2024 |
0.1.9-hotfix | 106 | 7/15/2024 |
0.1.8 | 109 | 7/8/2024 |
0.1.7 | 107 | 7/7/2024 |
0.1.6 | 163 | 1/23/2024 |
0.1.6-hotfix | 144 | 1/23/2024 |
0.1.5 | 122 | 1/22/2024 |
0.1.4 | 151 | 1/11/2024 |
0.1.3 | 127 | 1/10/2024 |
0.1.2 | 136 | 1/9/2024 |
0.1.1 | 139 | 1/9/2024 |
0.1.0 | 145 | 1/8/2024 |
0.0.9 | 157 | 12/27/2023 |
0.0.8 | 145 | 12/26/2023 |
0.0.7 | 156 | 9/8/2023 |
0.0.6 | 149 | 8/8/2023 |
0.0.5 | 166 | 7/31/2023 |
0.0.4 | 144 | 7/27/2023 |
0.0.3 | 187 | 7/20/2023 |
0.0.2 | 164 | 7/20/2023 |
0.0.1 | 159 | 7/19/2023 |