Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.Messaging - why MessageQueue does not offer an asynchronous version of Send

Would anyone know why System.Messaging is not offering an asynchronous version of the Send method to send an MSMQ message to a queue.

Actually there is asynchronous version of Peek and Receive methods (via Begin/End pairs that can be converted to a C#5 async awaitable method), but surprinsingly there is no BeginSend/EndSend methods offered, just a Send method which seems to me like it's a synchronous blocking I/O call.

I think this is not a limitation of System.Messaging but rather one of the native messaging queue API (mqrt.dll) that System.Messaging is using which takes an overlapped structure as a parameter in function MQReceiveMessage to use overlapping I/O with IOCP, whereas function MQsendMessage does not take such structure so seems like it's a purely synchronous call.

Still my question remains, anyone would know why MessageQueue API does not offer an asynchronous way of sending a message to a queue ?

like image 923
darkey Avatar asked Nov 02 '13 21:11

darkey


1 Answers

The MSMQ documentation states that a send is "always an asynchronous operation". It's been a while since I've worked with MSMQ, but IIRC as soon as you send, the message is flushed to disk locally before it even attempts to send over the network.

So, while it's not truly asynchronous (it has to wait for the disk write), it should be fairly fast.

like image 69
Stephen Cleary Avatar answered Sep 21 '22 20:09

Stephen Cleary