Wrappit 1.1.8

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

// Install Wrappit as a Cake Tool
#tool nuget:?package=Wrappit&version=1.1.8

Wrappit

Wrappit logo

Wrappit is a simple wrapper around RabbitMQ which makes it easier to both send and recieve messages from RabbitMQ.

Note: Currently, Wrappit only supports Topical exchanges with no plans on supporting other types of exchanges.

Usage

Configuration

To use Wrappit, use the following method in the services:


builder.Services.AddWrappit(new WrappitOptions
{
    HostName = "...",
    Port = 1234,
    UserName = "...",
    Password = "...",
    ExchangeName = "...",
    QueueName = "...",
    // Optionally add the following:
    DeliveryLimit = 5,
    DurableQueue = false,
    DurableExchange = false,
    AutoDeleteQueue = true,
});

These options can be ommitted if the following environment variables have been set:

  • Wrappit_HostName.
  • Wrappit_Port.
  • Wrappit_UserName.
  • Wrappit_Password.
  • Wrappit_ExchangeName.
  • Wrappit_QueueName.
  • Optional variables:
    • Wrappit_DeliveryLimit. The default is 10. This delivery limit is used when a handle method fails, this prevents infinite requeuing (see the related issue).
    • Wrappit_DurableQueue.
    • Wrappit_DurableExchange.
    • Wrappit_AutoDeleteQueue.

Once all of the environment variables have been set, the following can be done:

builder.Services.AddWrappit();

Listening to events

Listening to a certain event is easy, simply add the [EventListener] and [Handle("Topic")] Attributes. The handle method requires exactly one parameter, which is the Event. This event needs to inherit from the class DomainEvent:

using Wrappit.Messaging;

public class ExampleEvent : DomainEvent 
{
    public string ExampleProperty { get; set; }
}

By default, the DomainEvent class has a CorrelationId and a DateTime property (for debugging messages).

using Wrappit.Attributes;

[EventListener]
public class SimpleListener
{
    [Handle("Demo.Topic")]
    public void Handle(ExampleEvent e)
    {
        Console.WriteLine(e.ExampleProperty);
        Console.WriteLine(e.CorrelationId);
        Console.WriteLine(e.DateTime);
    }
}

It is also possible to use multiple Handlers in the same event listener class. It is also possible to have multiple handlers listen to the same topic, however, if one of these handlers fails the message will be requeued.

To allow complex logic to take place, it is also possible to use dependency injection in the EventListener class:

using Wrappit.Attributes;

[EventListener]
public class DependencyInjectionListener
{
    private readonly IExample _example;

    public DependencyInjectionListener(IExample example)
    {
        _example = example;
    }

    [Handle("Demo.Topic")]
    public void Handle(ExampleEvent @event)
    {
        _example.DoStuff();
    }
}

Lastly, it is also possible for the Handle method to be asynchronous:

[EventListener]
public class AsyncListener
{
    [Handle("Demo.Async")]
    public async Task HandleAsync(ExampleEvent @event)
    {
        await Task.Delay(2000);
        Console.WriteLine(@event.ExampleProperty);
    }
}

Publishing an event

Publishing an event is even easier, simply add the IWrappitPublisher to your constructor. Dependency injection will take care of the rest:

using Wrappit.Messaging;

public class MessageController
{
    private readonly IWrappitPublisher _publisher;

    public MessageController(IWrappitPublisher publisher)
    {
        _publisher = publisher;
    }

    [HttpPost]
    public void Send(string message)
    {
        _publisher.Publish("Demo.Topic", new ExampleEvent { ExampleProperty = message });
    }
}

Bugs?

Please make an issue, I will take a look at it (if time allows).

Product 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
1.1.8 8,331 1/10/2023
1.1.7 277 1/9/2023
1.1.6 294 12/23/2022
1.1.5 275 12/20/2022
1.1.4 282 12/16/2022
1.1.3 271 12/16/2022
1.1.2 275 12/15/2022
1.1.1 289 12/10/2022
1.1.0 268 12/9/2022
1.0.1 264 12/9/2022
1.0.0 260 12/9/2022