MSMQ (Microsoft Message Queuing) helper library
Install-Package MsmqExts
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
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
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]
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
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
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
var messageQueue = new MsmqMessageQueue(".\\private$\\hungvo-hello");
var obj = new Product
{
Id = 1,
Name = @"Jin"
};
messageQueue.Enqueue(obj);
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();
}
- Support for immutable messages
- Use very low CPU/RAM
- Transaction
- Batch enqueue/dequeue messages
- Support netstandard2.0 & net462
- Message persistence in mind
- Create a MSMQ transaction queue
- Update queue name (
AppConstants.MyQueueName
) - Run Publisher - Consumer
- Enjoy
Inspired by https://www.hangfire.io