Skip to content

minhhungit/MsmqExts

Repository files navigation

MsmqExts

MSMQ (Microsoft Message Queuing) helper library

Install

Install-Package MsmqExts

Performance (Transaction queue)

Single message producer

Enqueued 1 message in 0.26ms
Enqueued 1 message in 0.26ms
Enqueued 1 message in 0.27ms
Enqueued 1 message in 0.28ms
Enqueued 1 message in 0.29ms
Enqueued 1 message in 0.27ms

Single message producer using C# Parallel

Enqueued 10000 messages(s) in 975.02ms, avg 0.1ms per message
Enqueued 10000 messages(s) in 877.55ms, avg 0.09ms per message
Enqueued 10000 messages(s) in 866.62ms, avg 0.09ms per message
Enqueued 10000 messages(s) in 928.88ms, avg 0.09ms per message
Enqueued 10000 messages(s) in 909.85ms, avg 0.09ms per message

Single message consumer

Got a product in 0.12ms | [<11806 / 998a6e0> - 21:12:12.710]
Got a product in 0.18ms | [<11807 / a0e25a3> - 21:12:12.710]
Got a product in 0.14ms | [<11808 / fc7c5e0> - 21:12:12.710]
Got a product in 0.15ms | [<11809 / 23bd871> - 21:12:12.710]
Got a product in 0.12ms | [<11810 / 5e8cb24> - 21:12:12.710]
Got a product in 0.14ms | [<11811 / 99d2df1> - 21:12:12.710]

Batch messages producer

Enqueued a batch 50000 message(s) in 1853.38ms, avg 0.04ms per message
Enqueued a batch 50000 message(s) in 1750.66ms, avg 0.04ms per message
Enqueued a batch 50000 message(s) in 1796.26ms, avg 0.04ms per message
Enqueued a batch 50000 message(s) in 1927.82ms, avg 0.04ms per message
Enqueued a batch 50000 message(s) in 1916.92ms, avg 0.04ms per message

Batch messages consumer - batchSize 10_000

Tried to fetch a batch 10000 messages, got 10000/10000, avg 0.04ms per message
Tried to fetch a batch 10000 messages, got 10000/10000, avg 0.04ms per message
Tried to fetch a batch 10000 messages, got 10000/10000, avg 0.04ms per message
Tried to fetch a batch 10000 messages, got 10000/10000, avg 0.04ms per message
Tried to fetch a batch 10000 messages, got 10000/10000, avg 0.04ms per message

Batch message consumer - batchSize 50_000

Tried to fetch a batch 50000 messages, got 50000/50000, avg 0.05ms per message
Tried to fetch a batch 50000 messages, got 50000/50000, avg 0.04ms per message
Tried to fetch a batch 50000 messages, got 50000/50000, avg 0.04ms per message
Tried to fetch a batch 50000 messages, got 50000/50000, avg 0.04ms per message
Tried to fetch a batch 50000 messages, got 50000/50000, avg 0.04ms per message

Demo

Simple Publisher

var messageQueue = new MsmqMessageQueue(".\\private$\\hungvo-hello");
var obj = new Product
{
    Id = 1,
    Name = @"Jin"
};

messageQueue.Enqueue(obj);

Simple Consumer

CancellationTokenSource tokenSource = new CancellationTokenSource();
CancellationToken token = tokenSource.Token;

var msmqMessageQueue = new MsmqMessageQueue(".\\private$\\hungvo-hello");

try
{
    var message = _messageQueue.Dequeue(token);
    if (message.Result is Product prod)
    {
        Console.WriteLine($"- processing product <{prod.Id}>");
    }
    message.Commit();
}
catch (Exception ex)
{
    Console.WriteLine($"Error: {ex.Message}");
    message.Abort();
}

Check more samples here

Feature:

  • Support for immutable messages
  • Use very low CPU/RAM
  • Transaction
  • Batch enqueue/dequeue messages
  • Support netstandard2.0 & net462
  • Message persistence in mind

How to run sample:


Inspired by https://www.hangfire.io

About

MSMQ (Microsoft Message Queuing) helper library

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages