GithubHelp home page GithubHelp logo

forki / alicemq Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jkone27/alicemq

0.0 3.0 0.0 564 KB

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

License: MIT License

C# 100.00%

alicemq's Introduction

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

alicemq's People

Contributors

jkone27 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.