Imani.Solutions.RabbitMQ
0.0.1
dotnet add package Imani.Solutions.RabbitMQ --version 0.0.1
NuGet\Install-Package Imani.Solutions.RabbitMQ -Version 0.0.1
<PackageReference Include="Imani.Solutions.RabbitMQ" Version="0.0.1" />
paket add Imani.Solutions.RabbitMQ --version 0.0.1
#r "nuget: Imani.Solutions.RabbitMQ, 0.0.1"
// Install Imani.Solutions.RabbitMQ as a Cake Addin #addin nuget:?package=Imani.Solutions.RabbitMQ&version=0.0.1 // Install Imani.Solutions.RabbitMQ as a Cake Tool #tool nuget:?package=Imani.Solutions.RabbitMQ&version=0.0.1
rabbitmq-dotNet-showCase
This is a reference DotNet Core client/wrapper for connecting with RabbitMQ. It demonstrates the best practice development techniques.
This project implements the builder design pattern for producers and consumers.
Environments or Input Properties
This module uses the ConfigSettings object from the open source Imani Solutions DotNet API. This supports getting string, numbers, secrets or encrypted passwords properties from input arguments or environment variables.
You can set the properties using an environment variable or input argument (prefixed with --PROPERTY_NAME).
PROPERTY | Notes | Default |
---|---|---|
CRYPTION_KEY | Password encryption salt key | |
RABBIT_HOST | Host name | localhost |
RABBIT_PORT | Listen port | 5672 |
RABBIT_CONNECTION_RETRY_SECS | Automatic reconnect time interval | 15 |
RABBIT_VIRTUAL_HOST | The rabbit virtual host | / |
RABBIT_USERNAME | The rabbit username | |
RABBIT_PASSWORD | The encrypted rabbit password with value from applications/password-encryption | |
RABBIT_URI | Supports multiple hosts/ports and TLS/SLL in a rabbit cluster ex: "amqps://guest:guest@localhost:5671/" | |
RABBIT_CLIENT_NAME | The client provided name | |
RABBIT_WAIT_FOR_CONFIRMATION_SECS | Publish wait for connection | 30 |
RABBIT_PREFETCH_LIMIT | Prefetch limit (mainly for consumers) | 1000 |
Sample Code
Consumer Code
Rabbit rabbit = Rabbit.Connect();
var consumer = rabbit.ConsumerBuilder()
.SetExchange(exchange)
.AddQueue(queue,expectedRoutingKey)
.Build();
consumer.RegisterReceiver(receiver);
private void receiver(IModel channel, object sender, BasicDeliverEventArgs eventArg)
{
var actual = Encoding.UTF8.GetString(eventArg.Body.ToArray());
channel.BasicAck(eventArg.DeliveryTag,false);
}
Publisher Code
var msg = Encoding.UTF8.GetBytes(expectedMsg);
RabbitPublisher publisher = subject.PublishBuilder().
SetExchange(exchange)
.AddQueue(queue,expectedRoutingKey)
.Build();
string routingKey = "";
publisher.Publish(msg, routingKey);
Best Practices
Client Side
- Use Quorum queues for consistency
- Enable auto reconnect for connections
- Use one connection per process
- Use one channel per thread
- Enable handlers to detect blocked connections'
- Use Durable exchanges, durable queues and persistent messages for reliablity
- Set auto delete on temporary queues
- Set client name to assist with identifying application connections
- Keep exchange names the same case for producers and consumers
Client Publisher Side
- Use Publisher confirms for consistency
- Add a handler for BasicReturn when messages not routed to a queue
- Set the mandatory message property to true to prevent Unroutable messages.
Client Consumer Side
- Use manual ACK for consumers per message
- Set Prefetch limit for consumers
- Set the prefetch limit (round trip latency/processing time) (ex: MAX 1K)
- If you use dead letter exchanges/queues set to a very high count since DLX do not support confirmation and can lost messages
- Use consumer (push) over get (pull)
- Name queues based on patterns of routing keys where applicable
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 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. |
This package has no dependencies.
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.0.1 | 180 | 10/16/2022 |
RabbitMQ API.