NanoRabbit 0.1.2
See the version list below for details.
dotnet add package NanoRabbit --version 0.1.2
NuGet\Install-Package NanoRabbit -Version 0.1.2
<PackageReference Include="NanoRabbit" Version="0.1.2" />
<PackageVersion Include="NanoRabbit" Version="0.1.2" />
<PackageReference Include="NanoRabbit" />
paket add NanoRabbit --version 0.1.2
#r "nuget: NanoRabbit, 0.1.2"
#addin nuget:?package=NanoRabbit&version=0.1.2
#tool nuget:?package=NanoRabbit&version=0.1.2
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.
NanoRabbit is under development! Please note that some APIs may change their names or usage!
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.0.2, 0.0.3, 0.0.4, 0.0.5, 0.0.6 | 6.5.0 | 6.0 |
0.0.7 | 6.5.0 | 6.0, 7.0, 8.0 |
0.0.8, 0.0.9 | 6.7.0 | 6.0, 7.0, 8.0 |
0.1.0, 0.1.1, 0.1.2 | 6.8.1 | 6.0, 7.0, 8.0 |
Document
The NanoRabbit Document is at NanoRabbit Wiki.
QuickStart
NanoRabbit is designed as a library depends on NAMING Producers, Consumers. So it's important to set a UNIQUE NAME for each Producers, Consumers.
For more, please visit the Examples.
Create a RabbitProducer && RabbitConsumer
RabbitProducer
Register a RabbitMQ Producer by calling RabbitProducer()
, and configure it.
var producer = new RabbitProducer(new[]
{
new ProducerOptions
{
ProducerName = "FooFirstQueueProducer",
HostName = "localhost",
Port = 5672,
UserName = "admin",
Password = "admin",
VirtualHost = "FooHost",
ExchangeName = "amq.topic",
RoutingKey = "FooFirstKey",
Type = ExchangeType.Topic,
Durable = true,
AutoDelete = false,
AutomaticRecoveryEnabled = true
}
});
RabbitConsumer
Register a RabbitMQ Consumer by calling RabbitConsumer()
, and configure it.
var consumer = new RabbitConsumer(new[]
{
new ConsumerOptions
{
ConsumerName = "FooSecondQueueConsumer",
HostName = "localhost",
Port = 5672,
UserName = "admin",
Password = "admin",
VirtualHost = "FooHost",
QueueName = "FooSecondQueue",
AutomaticRecoveryEnabled = true
}
});
Simple Publish
After creating the RabbitProducer
, you can simply publish a message by calling Publish<T>()
.
producer.Publish<string>("FooFirstQueueProducer", "Hello");
Simple Consume
After creating the RabbitConsumer
, you can simply consume a message by
inheriting RabbitSubscriber
.
public class ConsumeService : RabbitSubscriber
{
public ConsumeService(IRabbitConsumer consumer, ILogger<RabbitSubscriber>? logger) : base(consumer, logger)
{
// ...
}
protected override bool HandleMessage(string message)
{
// ...
return true;
}
}
var consumeService = new ConsumeService(consumer, null, "FooSecondQueueConsumer");
consumeService.StartAsync(CancellationToken.None);
Forward messages
Working on it.
DependencyInjection
AddRabbitProducer
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddRabbitProducer(options =>
{
options.AddProducer(new ProducerOptions
{
ProducerName = "FooFirstQueueProducer",
HostName = "localhost",
Port = 5672,
UserName = "admin",
Password = "admin",
VirtualHost = "FooHost",
ExchangeName = "amq.topic",
RoutingKey = "FooFirstKey",
Type = ExchangeType.Topic,
Durable = true,
AutoDelete = false,
Arguments = null,
AutomaticRecoveryEnabled = true
});
options.AddProducer(new ProducerOptions
{
ProducerName = "BarFirstQueueProducer",
HostName = "localhost",
Port = 5672,
UserName = "admin",
Password = "admin",
VirtualHost = "BarHost",
ExchangeName = "amq.direct",
RoutingKey = "BarFirstKey",
Type = ExchangeType.Direct,
Durable = true,
AutoDelete = false,
Arguments = null,
AutomaticRecoveryEnabled = true
});
});
AddRabbitConsumer
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddRabbitConsumer(options =>
{
options.AddConsumer(new ConsumerOptions
{
ConsumerName = "FooFirstQueueConsumer",
HostName = "localhost",
Port = 5672,
UserName = "admin",
Password = "admin",
VirtualHost = "FooHost",
QueueName = "FooFirstQueue",
AutomaticRecoveryEnabled = true
});
options.AddConsumer(new ConsumerOptions
{
ConsumerName = "BarFirstQueueConsumer",
HostName = "localhost",
Port = 5672,
UserName = "admin",
Password = "admin",
VirtualHost = "BarHost",
QueueName = "BarFirstQueue", AutomaticRecoveryEnabled = true
});
});
AddRabbitSubscriber
After adding RabbitConsumer
and inheriting RabbitSubscriber
, you should register the BackgroundService
by AddRabbitSubscriber
:
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddRabbitSubscriber<ConsumeService>("FooSecondQueueConsumer");
Using producer or consumer
Then, you can use RabbitProducer and RabbitConsumer at anywhere.
For example:
public class PublishService : BackgroundService
{
private readonly IRabbitProducer _producer;
public PublishService(IRabbitProducer producer)
{
_producer = producer;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
_producer.Publish("FooFirstQueueProducer", "Hello from conn1");
_producer.Publish("BarFirstQueueProducer", "Hello from conn2");
await Task.Delay(1000, stoppingToken);
}
}
}
More DI 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 support
- DependencyInjection support
- Logging support
- Forward messages
- ASP.NET support
- Exchange Configurations
- .NET 7 support
- .NET 8 support
- Caching of failed sends
Thanks
- Visual Studio 2022
- RabbitMQ.Client
- Newtonsoft.Json
- Masstransit
- EasyNetQ
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 (>= 7.0.0)
- Microsoft.Extensions.Logging (>= 7.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 7.0.1)
- Microsoft.Extensions.Logging.Console (>= 7.0.0)
- Newtonsoft.Json (>= 13.0.3)
- RabbitMQ.Client (>= 6.8.1)
-
net7.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 7.0.0)
- Microsoft.Extensions.Logging (>= 7.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 7.0.1)
- Microsoft.Extensions.Logging.Console (>= 7.0.0)
- Newtonsoft.Json (>= 13.0.3)
- RabbitMQ.Client (>= 6.8.1)
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 7.0.0)
- Microsoft.Extensions.Logging (>= 7.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 7.0.1)
- Microsoft.Extensions.Logging.Console (>= 7.0.0)
- Newtonsoft.Json (>= 13.0.3)
- RabbitMQ.Client (>= 6.8.1)
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 | 167 | 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 |