导出 (0) 打印
全部展开

OnMessageOptions 类

注:本页面内容可能不完全适用中国大陆地区运营的 Windows Azure服务。如要了解不同地区 Windows Azure 服务的差异, 请参考本网站.

System..::..Object
  Microsoft.ServiceBus.Messaging..::..OnMessageOptions

命名空间:  Microsoft.ServiceBus.Messaging
程序集:  Microsoft.ServiceBus(在 Microsoft.ServiceBus.dll 中)

public final class OnMessageOptions

OnMessageOptions 类型公开以下成员。

  名称说明
公共方法OnMessageOptions初始化 OnMessageOptions 类的新实例。
页首

  名称说明
公共属性AutoComplete获取或设置一个值,用于指示消息泵是否应在回调完成处理后对消息调用 Complete(Guid)Complete(Guid)
公共属性AutoRenewTimeout获取或设置会话自动续订所需的时间。
公共属性MaxConcurrentCalls获取或设置消息泵应启动的回调的最大并发调用数。
页首

  名称说明
公共方法Equals (从 Object 继承。)
公共方法GetHashCode (从 Object 继承。)
公共方法GetType (从 Object 继承。)
公共方法ToString (从 Object 继承。)
页首

  名称说明
公共事件ExceptionReceived当收到异常时发生。使你可以收到有关消息泵遇到的任何错误的通知。
页首

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();
            }
        }

此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。不保证所有实例成员都是线程安全的。

社区附加资源

添加
Microsoft 正在进行一项网上调查,以了解您对 MSDN 网站的意见。 如果您选择参加,我们将会在您离开 MSDN 网站时向您显示该网上调查。

是否要参加?
显示:
© 2014 Microsoft