Aoxe.RabbitMQ.Abstractions 2024.1.1

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

// Install Aoxe.RabbitMQ.Abstractions as a Cake Tool
#tool nuget:?package=Aoxe.RabbitMQ.Abstractions&version=2024.1.1                

Aoxe.RabbitMQ

RabbitMQ is the most widely deployed open source message broker.

With more than 35,000 production deployments of RabbitMQ world-wide at small startups and large enterprises, RabbitMQ is the most popular open source message broker.

RabbitMQ is lightweight and easy to deploy on premises and in the cloud. It supports multiple messaging protocols. RabbitMQ can be deployed in distributed and federated configurations to meet high-scale, high-availability requirements (GitHub).

QuickStart

NuGet

Install-Package Aoxe.RabbitMQ
Install-Package Aoxe.NewtonsoftJson

In addition we have the following json serializers:

Aoxe.Jil

Aoxe.SystemTextJson

Aoxe.Utf8Json

Asp.net core

Import reference in startup.cs

using Aoxe.RabbitMQ;
using Aoxe.RabbitMQ.Abstractions;
using Aoxe.NewtonsoftJson;

Register AoxeRabbitMqClient in ConfigureServices method

services.AddSingleton<IAoxeRabbitMqClient>(_ =>
    new AoxeRabbitMqClient(new AoxeRabbitMqOptions
    {
        AutomaticRecoveryEnabled = true,
        Hosts = new List<string> { `192.168.78.130` },
        UserName = `admin`,
        Password = `123`,
        Serializer = new NewtonsoftJson.Serializer()
    }));

Create a message class named TestEvent and version control it with the MessageVersion attribute.

public class TestEvent
{
    public Guid Id { get; set; }
    public DateTime CreateTime { get; set; }
}
[MessageVersion(`3.14`)]
public class TestEventWithVersion
{
    public Guid Id { get; set; }
    public DateTime CreateTime { get; set; }
}

Publish

In Aoxe.RabbitMQ we distinguish the different publishing methods by message type and message sending type as follows:

void PublishEvent<T>(T @event);
void PublishEvent<T>(string topic, T @event);
void PublishEvent(string topic, byte[] body);

void SendCommand<T>(T command);
void SendCommand(string topic, T command);
void SendCommand(string topic, byte[] body);

void PublishMessage<T>(T message);
void PublishMessage<T>(string topic, T message);
void PublishMessage(string topic, byte[] body);

There are two concepts here, message type and message sending type

  • Message type
    • Message: The Message type will not be persisted for throughput and performance purposes, and messages will not be transferred to the dead message queue in the event of a consumption exception. The message's exchange is also Durable to false, so the exchange will be lost after the broker restarts.
    • Event: Messages of event type will be persisted and will be transferred to the corresponding dead message queue in case of consumption exceptions. The Durable of event's exchange is true, so that it is not lost when the broker restarts.
    • Command: An Event represents something that has already happened, and the publisher does not care whether or not any consumer cares about the event, or what it does with the event. A command represents a message that the publisher expects a consumer to process. So PublishEvent just posts the event to the exchange, and doesn't create a queue; send command creates a queue with the same name as the exchange / topic, and expects someone to handle it.
  • Message sending type
    • Publish: The message will be posted to the corresponding Topic (which is actually the wrapper for the exchange in RabbitMQ), and if there is no queue binding to the exchange, the message will be discarded.
    • Send: When messages are sent to RabbitMQ, a default queue is created in addition to the corresponding exchange (if there is none), and the exchange and queue will be named after the topic.

Subscribe

As with publish, there are several different methods of subscribing:

void SubscribeEvent<T>(Func<Action<T?>> resolve, ushort prefetchCount = 10, int consumeRetry = Consts.DefaultConsumeRetry, bool dlx = true);
void SubscribeEvent<T>(Func<Func<T?, Task>> resolve, ushort prefetchCount = 10, int consumeRetry = Consts.DefaultConsumeRetry, bool dlx = true);
void SubscribeEvent<T>(string topic, Func<Action<T?>> resolve, ushort prefetchCount = 10, int consumeRetry = Consts.DefaultConsumeRetry, bool dlx = true);
void SubscribeEvent<T>(string topic, Func<Func<T?, Task>> resolve, ushort prefetchCount = 10, int consumeRetry = Consts.DefaultConsumeRetry, bool dlx = true);

void ReceiveCommand<T>(Func<Action<T?>> resolve, ushort prefetchCount = 10);
void ReceiveCommand<T>(Func<Func<T?, Task>> resolve, ushort prefetchCount = 10);
void ReceiveCommand<T>(string topic, Func<Action<T?>> resolve, ushort prefetchCount = 10);
void ReceiveCommand<T>(string topic, Func<Func<T?, Task>> resolve, ushort prefetchCount = 10);

void ListenMessage<T>(Func<Action<T?>> resolve, ushort prefetchCount = 10);
void ListenMessage<T>(Func<Func<T?, Task>> resolve, ushort prefetchCount = 10);
void ListenMessage<T>(string topic, Func<Action<T?>> resolve, ushort prefetchCount = 10);
void ListenMessage<T>(string topic, Func<Func<T?, Task>> resolve, ushort prefetchCount = 10);
  • Subscribe: Will automatically create (if not already) a queue named by resolve to bind to the exchange and consume it. And it can set the consume retry count, if it still process fail, the event will be sent to the dlx queue.
  • Receive: As opposed to Send, will consume messages from the queue created by send.
  • Listen: We know that multiple nodes subscribe / receive to the same queue, the messages in this queue will be pushed to these nodes to achieve a balanced load, that is, a single message will only be consumed by a single node in the cluster; while Listen allows a single node to have an independent exclusive queue, and automatically delete this queue when the connection is disconnected, usually used in scenarios where all nodes need to be notified.

Also these methods corresponding asynchronous versions too.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Aoxe.RabbitMQ.Abstractions:

Package Downloads
Aoxe.RabbitMQ.Client

An easy-to-use and robust RabbitMQ client.

Aoxe.DDD.MessageBus.RabbitMQ

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2024.1.1 392 9/6/2024
2024.1.0 186 6/13/2024