I'm testing NServiceBus with Azure Queue backend. I configured NServiceBus using all the default settings and have this code to send a message:
while ((data = Console.ReadLine()) != null)
{
Stopwatch sw = new Stopwatch();
sw.Start();
Bus.Send("testqueue", new Message() {Data = data});
sw.Stop();
Console.WriteLine("Sent time: " + sw.ElapsedMilliseconds);
}
When running on my dev machine, it takes ~700ms to send a message to the queue. The queue is far away, ~350ms when writing directly using Azure Storage client.
Now I have two questions:
- I don't want the thread to block on the Bus.Send call. One option is to the use async\await pattern. Another option is to have an in memory queue for delivering messages, similarly to 0MQ. The last option doesn't guarantee delivery of-course, but assuming there are some monitoring capabilities, I can live with that.
- Why does sending a message take twice the time of a simple write to the queue? Can this be optimized?