Skip to content
/ AliceMQ Public
forked from jkone27/AliceMQ

Simplied proxy for RabbitMq.Client library, with observables, ack and nack capabilities

License

Notifications You must be signed in to change notification settings

forki/AliceMQ

 
 

Repository files navigation

AliceMQ

An easy to use frontend for MQ system (now supporting RabbitMq only, but would be nice to extend to other systems) using Reactive Extensions and a Publish/Subscribe paradigm.

contributions welcome

Mailman (Producer)

Usage of a mailman is dead simple:

using AliceMQ.MailMan; //..

var source = new Source("A", "A.q");
var endPoint = new EndPoint();
var sink = new Sink(source);

var serialization = new JsonSerializerSettings
    {
        MissingMemberHandling = MissingMemberHandling.Error
    };

 var p = new Mailman(endPoint, source.Exchange, s => JsonConvert.SerializeObject(s, serialization));

//first message published creates exchange if non existent
p.PublishOne(new Msg(-1),"");

Now let's see the simplest form of consumer, which is just a thin layer from the real MQ system...

SimpleMailbox (Consumer of BasicDeliverEventArgs)

Consumer subscription is identical for every type, giving an istance of an IObservable (rx).

using AliceMQ.Mailbox;

var mb = new SimpleMailbox(endPoint, sink);

var d = mb.Subscribe(am =>
{
    Console.WriteLine("A - " + Encoding.UTF8.GetString(am.EventArgs.Body));
    am.Channel.BasicAck(am.EventArgs.DeliveryTag, false);
});

//...
d.Dispose();

Mailbox<T> (Consumer of T)

let's consider an example DTO class Msg, the typed consumer is build upon the common consumer, which is enhanced with message body deserialization into an istance of a generic T type.

var sfm = new Mailbox<Msg>(endPoint, sink, s => JsonConvert.DeserializeObject<Msg>(s, serialization));

var d = sfm.Subscribe(am =>
{
    if (am.IsOk<Msg>())
    {
        var msg = am.AsOk<Msg>().Message;
        Console.WriteLine("ok - " + msg.Bla);
        am.Confirm();
    }
    else
    {
        Console.WriteLine("error - " + am.AsError().Ex.Message);
        am.Reject();
    }
},
ex => Console.WriteLine("COMPLETE ERROR"),
() => Console.WriteLine("COMPLETE"));

//...
d.Dispose();

Utility Types

Both Mailman and Mailbox need that you provide some basic parameters for configuring the Endpoint, the Source (namely Exchange and Queue), and the Mailbox (with more sofisticated configurations).

EndpointArgs

string ConnectionUrl
bool AutomaticRecoveryEnabled
TimeSpan NetworkRecoveryInterval

Source

IExchange Exchange
IQueueArgs QueueArgs

IExchange

string ExchangeName
string ExchangeType
bool Durable
bool AutoDelete
IDictionary<string, object> Properties

IQueueArgs

string QueueName
bool Durable
bool Exclusive
bool AutoDelete

Sink

string DeadLetterExchangeName
IDictionary<string, object> QueueDeclareArguments
Source Source
BasicQualityOfService BasicQualityOfService
ConfirmationPolicy ConfirmationPolicy 
QueueBind QueueBind

QueueBind

string RoutingKey
IDictionary<string, object> Arguments

BasicQualityOfService

ushort PrefetchCount
bool Global

ConfirmationPolicy

bool AutoAck
bool Multiple
bool Requeue

Status

Build Status

About

Simplied proxy for RabbitMq.Client library, with observables, ack and nack capabilities

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%