Was deze pagina nuttig?
Uw feedback over deze inhoud is belangrijk. Laat ons weten wat u denkt.
Aanvullende feedback?
1500 tekens resterend
Exporteren (0) Afdrukken
Alles uitvouwen
EN
Deze inhoud is niet beschikbaar in uw taal, maar wel in het Engels.

OnMessageOptions Class

Provides options associated with message pump processing using OnMessage(Action<BrokeredMessage>) and OnMessage(Action<BrokeredMessage>).

System.Object
  Microsoft.ServiceBus.Messaging.OnMessageOptions

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

public sealed class OnMessageOptions

The OnMessageOptions type exposes the following members.

  NameDescription
Public methodOnMessageOptionsInitializes a new instance of the OnMessageOptions class.
Top

  NameDescription
Public propertyAutoCompleteGets or sets a value that indicates whether the message-pump should call Complete(Guid) or Complete(Guid) on messages after the callback has completed processing.
Public propertyAutoRenewTimeoutGets or sets the needed time for the session to automatically renew.
Public propertyMaxConcurrentCallsGets or sets the maximum number of concurrent calls to the callback the message pump should initiate.
Top

  NameDescription
Public methodEquals (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Public methodToString (Inherited from Object.)
Top

  NameDescription
Public eventExceptionReceivedOccurs when exception is received. Enables you to be notified of any errors encountered by the message pump.
Top

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.");
    Console.ReadKey();
}

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

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

Community-inhoud

Toevoegen
Weergeven:
© 2015 Microsoft