Appfabric cache Notification problem
-
Tuesday, May 15, 2012 4:51 PM
Hi i have problem with notification receive , we have cache "Rates" attach configuration
and my code :
class Program
{
static DataCacheServerEndpoint cache_server = new DataCacheServerEndpoint("192.168.1.87", 22233);
static DataCacheFactoryConfiguration configuration = new DataCacheFactoryConfiguration();
static List<DataCacheServerEndpoint> servers;
static DataCache dtCache;
static void Main(string[] args)
{
servers = new List<DataCacheServerEndpoint>(1);
servers.Add(cache_server);
configuration.SecurityProperties = new DataCacheSecurity(DataCacheSecurityMode.None, DataCacheProtectionLevel.None);
configuration.Servers = servers;
configuration.NotificationProperties = new DataCacheNotificationProperties(1000, new TimeSpan(0, 0, 0, 0, 5));
configuration.LocalCacheProperties = new DataCacheLocalCacheProperties();
//Disable exception messages since this sample works on a cache aside
DataCacheClientLogManager.ChangeLogLevel(System.Diagnostics.TraceLevel.Info);
DataCacheFactory CacheFactory = null;
CacheFactory = new DataCacheFactory(configuration);
dtCache = CacheFactory.GetCache("Rates");
DataCacheOperations allCacheOperations;
allCacheOperations = DataCacheOperations.AddItem |
DataCacheOperations.ReplaceItem |
DataCacheOperations.RemoveItem;
DataCacheNotificationDescriptor dtnDesc2 = dtCache.AddItemLevelCallback("Rates", allCacheOperations, myCacheLvlDelegate);
Console.WriteLine("Ready for receive notifications");
Console.Read();
}
public static void myCacheLvlDelegate(string myCacheName,
string myRegion,
string myKey,
DataCacheItemVersion itemVersion,
DataCacheOperations OperationId,
DataCacheNotificationDescriptor nd)
{
//display some of the delegate parameters
Console.WriteLine("A cache-level notification was triggered!");
Console.WriteLine(" Cache: " + myCacheName);
Console.WriteLine(" Region: " + myRegion);
Console.WriteLine(" Key: " + myKey);
Console.WriteLine(" Operation: " + OperationId.ToString());
Console.WriteLine();
}
}i can update cache in push mode but i can't receive notification , why ?
Regards
Alex
- Moved by Ben Cline1MVP, Moderator Thursday, May 17, 2012 8:28 PM related to cache (From:AppFabric Service and Workflow Management)
All Replies
-
Monday, May 21, 2012 1:28 PM
Hello Alex,
There is a small bug in the code.
DataCacheNotificationDescriptor dtnDesc2 = dtCache.AddItemLevelCallback("Rates", allCacheOperations, myCacheLvlDelegate);
When you want ItemLevel Call back, the first parameter of AddItemLevelCallback is supposed to be the "key" (item) on which you want notifications [Where as you are specifying "cacheName"]. Documentation pointer - http://msdn.microsoft.com/en-us/library/ff424507(v=ws.10)
So, in your case if you want call back for various operations on the cache you need to use AddCacheLevelCallback - If you use this method you would get notification call backs for different operations as you specify in the method params.
Hope the difference is clear.
Thanks
Ranganath G
- Proposed As Answer by RanganathG [MSFT]Microsoft Employee Monday, May 21, 2012 1:29 PM

