Home

Awesome

Postal.NET

Introduction

Postal.NET is a .NET Standard library for writing decoupled applications. It is loosely based upon the Postal.js JavaScript library and follows somewhat the Domain Events and Pub/Sub patterns. It was written by Ricardo Peres (@rjperes75). As of version 2 it now targets .NET 8.

Concepts

Postal.NET uses the concepts of channels and topics. We subscribe to a topic of a channel, and we send messages to other (or possibly the same) channels and topics. The "*" character means anything, so, for example, "a.b" and "a.*" or even "*" will match. There can be several simultaneous subscriptions, even to the same channel/topic pair. Postal.NET guarantees the delivery.

Usage

//create a subscription to a single named channel and topic pair
using (Postal.Box.Subscribe("channel", "topic", (env) => Console.WriteLine(env.Data)))
{        
    //publish asynchronously (does not block)
    await Postal.Box.PublishAsync("channel", "topic", "Hello, Async World!");
}

//no consequences, since the subscription was terminated
await Postal.Box.PublishAsync("channel", "topic", "Does not appear because the subscription was disposed!");

A message can only be sent asynchronously and if there are subscribers to it, it will raise an event (one or more subscriptions being triggered). Subscriptions do not prevent the garbage collection of the subscriber. Messages are always wrapped in an envelope. There are some handy extensions for common tasks:

The public interface is decoupled from the actual implementation and it can be switched (but don't do it!).

You can find more examples in the GitHub repository in the Postal.NET.Test project.

Extensibility

Most of the inner workings of Postal.NET can be configured by injection an implementation of the core interfaces:

Installation

You can either:

Other Projects

Other projects you can find in the GitHub repository and in Nuget are:

Contacts

If you see any value in this and wish to send me your comments, please do so through GitHub. Questions and suggestions are welcome too!

Licenses

This software is distributed under the terms of the Free Software Foundation Lesser GNU Public License (LGPL), version 2.1 (see lgpl.txt).

Copyright

You are free to use this as you wish, but I ask you to please send me a note about it.