I use Masstransit
to work with RabbitMq
.
Below is the Publisher code :
// Publisher var bus = Bus.Factory.CreateUsingRabbitMq(x => { x.Host(new Uri("rabbitmq://localhost/"), h => { }); }); var busHandle = bus.Start(); for (int i = 0; i < int.MaxValue; i++) { bus.Publish(new Message() { Text = i.ToString() }); } busHandle.Stop(); Console.ReadKey();
and subsriber:
// Subsriber var bus = Bus.Factory.CreateUsingRabbitMq(x => { var host = x.Host(new Uri("rabbitmq://localhost/"), h => { }); x.ReceiveEndpoint(host, "TestSubscriber", e => e.Handler<Message>(a => { Console.WriteLine(a.Message.Text); return Task.FromResult(0); })); }); var busHandle = bus.Start(); Console.ReadKey(); busHandle.Stop();
If you look at the RabbitMq
metric,
You may notice that the number of messages that are published ( Publisher
) is an average of 7406
messages / second. And messages that are delivered ( Subsriber
) - 2531
messages / second. It turns out that the publisher ( Publisher
) publishes messages almost 3 times faster than the subscriber receives ( Subsriber
). This behavior is normal and is it possible to somehow speed up the process of receiving messages by the subscriber ( Subsriber
)?