ReceiveAsync
is a part of the ASB .NET client API. OnMessage
API is way the native ASB client offers to simplify creation of concurrent message pumps, allowing you a few features "out of the box" so that you don't have to handle those manually. Among those are:
- Easy registration of your message pump as a callback
- Message auto completion
- Auto renew timeout to simplify lock tokens renewal
- Handling of concurrent pumps/callbacks
These advantages can be also viewed as disadvantages when you need the flexibility and tight control over things. For example, if you need to control how message completion is performed, you'd turn auto completion off and do it yourself. But, when you need to process more than a single incoming message at a time in your callback, OnMessage API won't let you, since it's providing one message at a time, you better off with [ReceiveBatchAsync][1]
. I had a post about OnMessage API benefits you can review.
Which one should be picked in which particular scenario?
This is something you need to answer yourself based on what your requirements and architecture are going to be. If you do not require tight control over things and going to handle one message at a time (given you can execute concurrently multiple message processing), OnMessage API is an easy path to start with and ASB client does a good job. In case you need to process batches and control a lot of lower level aspects, go with MessageSender
/MessageReceiver
approach.