EzRabbitMq 0.1.0
Un releasing official versions to only keep pre-release ones before v1
See the version list below for details.
dotnet add package EzRabbitMq --version 0.1.0
NuGet\Install-Package EzRabbitMq -Version 0.1.0
<PackageReference Include="EzRabbitMq" Version="0.1.0" />
paket add EzRabbitMq --version 0.1.0
#r "nuget: EzRabbitMq, 0.1.0"
// Install EzRabbitMq as a Cake Addin #addin nuget:?package=EzRabbitMq&version=0.1.0 // Install EzRabbitMq as a Cake Tool #tool nuget:?package=EzRabbitMq&version=0.1.0
EzRabbitMq
Easy to use rabbitMq client.
Optional AppInsight consumer/ message / producer tracing.
Optional Logger.
Easy to use features.
Usage
Register services :
services.AddEzRabbitMq(config); // IConfiguration
Configuration
In AppSettings.json file or using environment variables :
{
"EzRabbitMq": {
"HostName": "localhost",
"UserName": "guest",
"Password": "guest",
"Port": 5672
}
}
Send direct message
IProducerService producerService; // use injection to get a IProducerService
producerService.Send(new DirectProducerOptions("ROUTING KEY"), new { Example = 123 });
Send topic message
IProducerService producerService; // use injection to get a IProducerService
producerService.Send(new TopicProducerOptions("ROUTING KEY"), new { Example = 123 });
Send fanout message
IProducerService producerService; // use injection to get a IProducerService
producerService.Send(new FanoutProducerOptions(), new { Example = 123 });
ProducerOptions
Implementation of IProducerOptions are helpers to simplify the producer definition.
E.g.: DirectProducerOptions is defaulting exchangeName to "amq.direct"
public enum DeliveryMode
{
NonPersistent = 1,
Persistent = 2 // default value
}
public interface IProducerOptions
{
public string RoutingKey { get; }
public string ExchangeName { get; }
public DeliveryMode DeliveryMode { get; }
}
Listen messages using events
You can create EventMailbox mailbox instance and react to messages with the OnMessageReceived event.
// use injection to get a IMailboxService
var mailboxOptions = new DirectMailboxOptions("ROUTING KEY", "MAILBOX NAME");
var mailbox = mailboxService.Create<EventMailbox<DataSample>>(mailboxOptions, new ConsumerOptions());
mailbox.OnMessageReceived += (sender, data) => {
// data is IMessage<DataSample>
};
Listen messages using implementation
Or you can implement your own Mailbox inheriting Mailbox<T>, you will have to implement the OnMessage method.
public class MyMailbox<T> : Mailbox<T>
{
public EventMailbox(
ILogger<MyMailbox<T>> logger,
IMailboxOptions options,
ISessionService session,
ConsumerOptions consumerOptions
) : base(logger, options, null, session, consumerOptions) { }
protected override void OnMessage(IMessage<T> data)
{
// react to message
}
}
// use injection to get a IMailboxService
var options = ConsumerOptions.CreateDefaultOptions;
var mailboxOptions = new DirectMailboxOptions("ROUTINg KEY", "MAILBOX NAME");
var mailbox = mailboxService.Create<MyMailbox<DataSample>>(mailboxOptions, options);
MailboxOptions
You can create you own MailboxOptions inheriting IMailboxOptions :
public enum ExchangeTypes
{
Direct,
Topic,
Fanout,
Headers
}
public interface IMailboxOptions
{
public string ExchangeName { get; }
public ExchangeTypes ExchangeType { get; }
public string RoutingKey { get; }
public string QueueName { get; }
}
ConsumerOptions
This options can add rabbitMq arguments to enable / disable features.
ConsumerOptions default values:
var options = new ConsumerOptions
{
AutoAck = true, // if AutoAck is false EzRabbit is gonna ack message only if no exception occured
QueueDurable = false, // set durable feature on queue (need queue recreation if changed)
QueueAutoDelete = false. // set auto delete feature on queue (need queue recreation if changed)
QueueExclusive = false, // set exclusive feature on queue (need queue recreation if changed)
QueueSizeLimit = 0, // set the queue size limit (need queued recreation)
ExchangeDurable = true, // set durable feature on exchange (need exchange recreation if changed)
ExchangeAutoDelete = false, // set auto delete feature on exchange (need exchange recreation if changed)
AckMultiple = false,
PrefetchLimit = 0,
PrefetchCount = 0, // set the prefetch amount of message read by this consumer
PrefetchGlobal = true,
// (on autoAck false and RequeueOnException false, exception will be considered as dead letter)
RequeueOnException = false,
DeadLetterExchangeName = null, // (string) set the DeadLetterExchangeName
DeadLetterRoutingKey = null, // (string) set the routing Key for dead letter
RetryCount = 0, // After 3 retry exception in the message will be reject,
QueueDeclareArguments = new Dictionary<string, object>(),
QueueBindArguments = new Dictionary<string, object>(),
ExchangeDeclareArguments = new Dictionary<string, object>()
};
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. 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 was computed. 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. |
-
net5.0
- Microsoft.ApplicationInsights.WorkerService (>= 2.18.0)
- Microsoft.Extensions.Configuration.Binder (>= 5.0.0)
- Microsoft.Extensions.Logging (>= 5.0.0)
- Polly (>= 7.2.2)
- RabbitMQ.Client (>= 6.2.2)
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 | |
---|---|---|---|
6.4.4 | 520 | 11/25/2023 | |
6.4.2 | 405 | 11/25/2023 | |
6.4.1 | 383 | 11/24/2023 | |
6.4.0 | 852 | 9/11/2022 | |
6.3.1 | 846 | 9/11/2022 | |
6.3.0 | 820 | 9/11/2022 | |
6.2.2.8 | 738 | 1/5/2022 | |
6.2.2.7 | 734 | 12/14/2021 | |
6.2.2.6 | 713 | 12/10/2021 | |
6.2.2.5 | 913 | 12/9/2021 | |
6.2.2.4 | 730 | 12/9/2021 | |
6.2.2.2 | 747 | 12/9/2021 | |
6.2.2.2-alpha | 596 | 12/5/2021 | |
6.2.2.1-alpha | 695 | 10/30/2021 | |
6.2.2-alpha | 640 | 10/28/2021 | |
0.2.0-beta002 | 638 | 10/25/2021 | |
0.2.0-beta001 | 682 | 10/25/2021 | |
0.2.0-alpha | 634 | 10/26/2021 | |
0.1.2 | 1,139 | 10/4/2021 | |
0.1.2-beta003 | 769 | 10/17/2021 | |
0.1.2-beta002 | 811 | 10/17/2021 | |
0.1.2-beta001 | 846 | 10/10/2021 | |
0.1.1 | 1,108 | 10/2/2021 | |
0.1.0 | 1,113 | 10/2/2021 | |
0.0.2-beta-3 | 756 | 9/26/2021 | |
0.0.2-beta-2 | 753 | 9/26/2021 | |
0.0.2-beta | 723 | 9/26/2021 | |
0.0.1 | 1,050 | 9/26/2021 |