添加失败通知回调

Microsoft AppFabric 1.1 for Windows Server 可以使启用缓存的应用程序接收缓存通知。本主题介绍了如何向应用程序添加失败通知回调。当缓存客户端丢失一个或多个缓存通知时将触发失败通知。有关缓存通知的常规详细信息,请参阅缓存通知(AppFabric 1.1 缓存)

与为缓存通知添加回调类似,为失败通知添加回调包含两个步骤。首先,创建一个在触发失败通知时调用的方法。失败通知调用的方法必须接受与 DataCacheFailureNotificationCallback 委派相同的参数。第二,使用 AddFailureNotificationCallback 方法为失败通知添加回调。为 failureDelegate 参数使用您在步骤一中创建的方法的名称。

备注

要想让您的应用程序使用通知,需要在命名缓存中启用它们。对 notificationsEnabledNew-Cache 命令使用 Set-CacheConfig 参数。有关详细信息,请参阅使用 Windows PowerShell 管理 AppFabric 1.1 缓存功能

添加失败通知回调的步骤

  1. 创建让失败通知触发的方法。确保失败通知调用的方法接受与 DataCacheFailureNotificationCallback 委托相同的参数。

  2. 使用 AddFailureNotificationCallback 方法为失败通知添加回调。在 failureDelegate 参数中使用失败通知发生时要调用的方法的名称。

示例

添加失败通知回调时,第一个步骤是创建一个让通知调用的方法。通知调用的方法必须接受与 DataCacheFailureNotificationCallback 委托相同的参数。此例演示了一个失败通知可调用的方法示例。

'method invoked by failure notification "ndNotificationFailure"
Public Sub myNotificationFailureDelegate(ByVal myCacheName As String, _
    ByVal nd As DataCacheNotificationDescriptor)

    Console.WriteLine("===============================")
    Console.WriteLine("Invoked by failure notification")
    Console.WriteLine("===============================")
End Sub
//method invoked by failure notification "ndNotificationFailure"
public void myNotificationFailureDelegate(string myCacheName,
    DataCacheNotificationDescriptor nd)
{
    Console.WriteLine("===============================");
    Console.WriteLine(" Invoked by failure notification");
    Console.WriteLine("===============================");
}

第二个步骤是为失败通知添加回调。在此示例中,创建了一个失败通知来调用前一个示例中的方法。

'add failure notification callback
Dim ndNotificationFailure As DataCacheNotificationDescriptor
ndNotificationFailure = _
    myTestCache.AddFailureNotificationCallback(AddressOf myNotificationFailureDelegate)
//add failure notification callback
DataCacheNotificationDescriptor ndNotificationFailure
    = myTestCache.AddFailureNotificationCallback(myNotificationFailureDelegate);

另请参阅

概念

添加缓存通知回调
删除缓存通知回调
缓存通知方法
使用 Windows PowerShell 管理 AppFabric 1.1 缓存功能

  2012-03-05