OnMessageOptions Class
De inhoudsopgave samenvouwen
De inhoudsopgave uitvouwen
Deze inhoud is niet beschikbaar in uw taal, maar wel in het Engels.

OnMessageOptions Class


Provides options associated with message pump processing using OnMessage and OnMessage.

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


public sealed class OnMessageOptions


Initializes a new instance of the OnMessageOptions class.


Gets or sets a value that indicates whether the message-pump should call Complete or Complete on messages after the callback has completed processing.


Gets or sets the maximum duration within which the lock will be renewed automatically. This value should be greater than the longest message lock duration; for example, the LockDuration Property.


Gets or sets the maximum number of concurrent calls to the callback the message pump should initiate.


(Inherited from Object.)


(Inherited from Object.)


(Inherited from Object.)


(Inherited from Object.)


Occurs when exception is received. Enables you to be notified of any errors encountered by the message pump.

When calling OnMessage, the client starts an internal message pump that constantly polls the queue or subscription. This message pump consists of an infinite loop that issues a Receive() call. If the call times out, it issues the next Receive() call. The timeout is the value of the OperationTimeout property of the MessagingFactory that is used. The default value of this timeout is 60 seconds. You can modify the timeout by changing the OperationTimeout property before creating the MessagingFactory. Note that every receive operation is a billable event.

void ReceiveMessages()
    // Initialize message pump options.
    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 get notified of any errors encountered by the message pump.

    // Start receiving messages.
    QueueClient client = QueueClient.Create("myQueue");
    client.OnMessage((receivedMessage) => // Initiates the message pump and callback is invoked for each message that is recieved, calling close on the client will stop the pump.
        // Process the message.
    }, options);

    Console.WriteLine("Press any key to exit.");

        void LogErrors(object sender, ExceptionReceivedEventArgs e)
            if (e.Exception != null)
                Console.WriteLine("Error: " + e.Exception.Message);

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
© 2015 Microsoft