SALES: 1-800-867-1380

SubscriptionClient.OnMessage Method (Action(Of BrokeredMessage), OnMessageOptions)


Processes a message in an event-driven message pump, with the given set of OnMessageOptions options.

Namespace:   Microsoft.ServiceBus.Messaging
Assembly:  Microsoft.ServiceBus (in Microsoft.ServiceBus.dll)

Public Sub OnMessage (
	callback As Action(Of BrokeredMessage),
	onMessageOptions As OnMessageOptions


Type: System.Action(Of BrokeredMessage)

The method to invoke when the operation is complete.

Type: Microsoft.ServiceBus.Messaging.OnMessageOptions

Specifies the OnMessageOptions options with which to instantiate the message pump.

OnMessageOptions options = new OnMessageOptions();
            options.AutoComplete = true; // Indicates if the message-pump should call complete on messages after the callback has completed processing.

            options.MaxConcurrentCalls = 1; // Indicates the maximum number of concurrent calls to the callback the pump should initiate 

            options.ExceptionReceived += LogErrors; // Enables you to be notified of any errors encountered by the message pump

            // Start receiveing messages
            Client.OnMessage((receivedMessage) => // Initiates the message pump and callback is invoked for each message that is received. Calling Close() on the client will stop the pump.

                    // Process the message
                    Trace.WriteLine("Processing", receivedMessage.SequenceNumber.ToString());
                }, options);
Return to top
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft