Skip to content

stone-payments/rabbitmq-abstraction

 
 

Repository files navigation

rabbitmq-abstraction

Client

using (var queueClient = new RabbitMQClient("localhost", 5672, "user", "password", "virtualHost"))
{
  //Do something
}

Publish

using (var queueClient = new RabbitMQClient("localhost", 5672, "user", "password", "virtualHost"))
{
  queueClient.Publish<string>("someExchange", "someRoute", "someObjectOfAnyReferenceType");
}

BatchPublish

using (var queueClient = new RabbitMQClient("localhost", 5672, "user", "password", "virtualHost"))
{
  queueClient.BatchPublish<string>("someExchange", "someRoute", 
    new[] {"someObjectOfAnyReferenceType", "otherObjectOfAnyReferenceType"});
}

SimpleConsume

using (var queueClient = new RabbitMQClient("localhost", 5672, "user", "password", "virtualHost"))
{
    var simpleMessageProcessingWorker = await SimpleMessageProcessingWorker<string>.CreateAndStartAsync(queueClient, "someQueue",
        Console.WriteLine, CancellationToken.None);

    simpleMessageProcessingWorker.Stop();
}

AsyncSimpleConsume

using (var queueClient = new RabbitMQClient("localhost", 5672, "user", "password", "virtualHost"))
{
    var simpleAsyncMessageProcessingWorker = await SimpleAsyncMessageProcessingWorker<string>.CreateAndStartAsync(queueClient,
        "someQueue", (message, innerCancellationToken) =>
        {
            Console.WriteLine(message);

            return Task.FromResult(0);
        }, TimeSpan.FromSeconds(10), CancellationToken.None);

    simpleAsyncMessageProcessingWorker.Stop();
}

AdvancedConsume

using (var queueClient = new RabbitMQClient("localhost", 5672, "user", "password", "virtualHost"))
{
    var advancedMessageProcessingWorker = await AdvancedMessageProcessingWorker<string>.CreateAndStartAsync(queueClient,
        "someQueue", Console.WriteLine, CancellationToken.None);

    advancedMessageProcessingWorker.Stop();
}

AsyncAdvancedConsume

using (var queueClient = new RabbitMQClient("localhost", 5672, "user", "password", "virtualHost"))
{
    var advancedAsyncMessageProcessingWorker = await AdvancedAsyncMessageProcessingWorker<string>.CreateAndStartAsync(queueClient,
        "someQueue", (message, innerCancellationToken) =>
        {
            Console.WriteLine(message);

            return Task.FromResult(0);
        }, TimeSpan.FromSeconds(10), CancellationToken.None);

    advancedAsyncMessageProcessingWorker.Stop();
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%