Răspuns propus Appfabric cache Notification problem

  • 15 mai 2012 16:51
     
     

    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 

    • Mutat de Ben Cline1MVP, Moderator 17 mai 2012 20:28 related to cache (From:AppFabric Service and Workflow Management)
    •  

Toate mesajele

  • 21 mai 2012 13:28
     
     Răspuns propus

    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