RabbitMQHare is a wrapper around RabbitMQ.Client for C#.
Informations about versions, dependencies, source repositories and contacts can be found in nuget.
Criteo used to have several rabbitmq-related libs with small code reuse and a lot of functionnal redundancy with the official client. Moreover, they lacked customizable failure handling.
We decided to provide a simple wrapper around RabbitMQ.Client that:
- provides simple yet powerful customisability
- tries to enforce a light and resilient use of rabbitmq objects
However we do not try to fill every need. Users that require strong insurances, full featured framework should use another lib or directly the official client.
Edge cases (connection failure for instance) might loose some messages. You should use this lib if you are ok with loosing some messages.
Publisher:
var settings = HarePublisherSettings.GetDefaultSettings();
RabbitPublisher.TemporaryConnectionFailure t = Console.WriteLine;
var random = new Random();
var exchange = new RabbitExchange("carrots");
var initialConnectionTries = 5;
var p = new RabbitPublisher(settings, exchange);
p.TemporaryConnectionFailureHandler += t
p.Start(initialConnectionTries);
for(var i=0;i<1000;++i)
p.Publish(random.Next().ToString(), new byte[0]);
Consumer:
var settings = HareConsumerSettings.GetDefaultSettings();
var exchange = new RabbitExchange("carrots");
var initialConnectionTries = 5;
BasicDeliverEventHandler messageHandler = (sender, e) =>
{
try
{
Console.WriteLine(e.Body);
}
catch (Exception ex)
{
Console.WriteLine("request treatment error" + ex);
}
};
RabbitConnectorCommon.TemporaryConnectionFailure pp = Console.WriteLine;
RabbitConnectorCommon.PermanentConnectionFailure ppp = Console.WriteLine;
var c = new RabbitConsumer(settings, exchange);
c.MessageHandler += messageHandler;
c.TemporaryConnectionFailureHandler += pp;
c.PermanentConnectionFailureHandler += ppp;
c.Start(initialConnectionTries);
Apache License v2. See accompanying LICENSE file for details
How-to:
Fork, commit, create a pull request. No contributor license agreement.
PR should have tests showing bug fixed by the commit or non-regression tests.