Asynchronous Message Processing
The AMPS C# client also supports an asynchronous interface. In this case, you add a message handler to the call to the subscribe. The client returns the command ID of the command submitted to AMPS, and returns once the server has acknowledged that the command has been processed. As messages arrive, AMPS calls your message handler directly on the background thread. This can be an advantage for some applications. For example, if your application is highly multithreaded and copies message data to a work queue processed by multiple threads, there may be a performance benefit to enqueuing work directly from the background thread. See the Understanding Threading section for a discussion of threading considerations, including considerations for message handlers.
As with the simple interface, the AMPS client provides both convenience interfaces and interfaces that use a Command
object. The following example shows how to use the asynchronous interface.
In the asynchronous interface, the AMPS client resets and reuses the message object provided to this lambda function between calls. This improves performance in the client, but means that if your handler function needs to preserve information contained within the message, you must copy the information rather than just saving the message object. Otherwise, the AMPS client cannot guarantee the state of the object or the contents of the object when your program goes to use it.
Last updated