Using Service Bus for Windows Server 1.1, trying to build out a asynchronous solution using the TPL methods that will work correctly. I'm using ReceiveMode.PeekLock and the throughput of the queue that I'm testing with is fantastic until I add the code to complete the brokered message at which point the throughput drops.
Here is the high throughput version:
public void Start() { _client.OnMessageAsync(MessageReceived); } private async Task MessageReceived(BrokeredMessage arg) { await Task.Run(() => { arg.GetBody<SampleMessage>(); }); }
This will rip through tens to hundreds msgs/sec.
When I add any version of the Complete() call, it drops to taking several seconds to process a single message. Some examples I've attempted below:
First attempt:
private async Task MessageReceived(BrokeredMessage arg) { await Task.Run(() => { arg.GetBody<SampleMessage>(); arg.Complete(); // or arg.CompleteAsync() }); }
Second Attempt:
private async Task MessageReceived(BrokeredMessage arg) { await Task.Run(() => { arg.GetBody<SampleMessage>(); }); await arg.CompleteAsync(); }
Third Attempt:
private async Task MessageReceived(BrokeredMessage arg) { await Task.Run(() => { arg.GetBody<SampleMessage>(); }).ContinueWith(t => arg.CompleteAsync()); }
I think these should be equivalent in their behavior, but all have the result of taking multiple seconds to process a single message.
I'm guessing that some sort of locking/blocking is taking place on queue operations, but I'm not sure how to diagnose this, and I haven't seen anything in the documentation suggesting so.
Any thoughts?
Thanks,
Andrew