问题描述
我有通知接收问题,我们有缓存"费率"附加配置
Hi i have problem with notification receive , we have cache "Rates" attach configuration
和我的代码:
课程
class Program
  {
      static DataCacheServerEndpoint cache_server = new DataCacheServerEndpoint(" 192.168.1.87",22233);
      static DataCacheFactoryConfiguration configuration = new DataCacheFactoryConfiguration();
&NBSP; &NBSP; &NBSP;静态列表< DataCacheServerEndpoint>服务器;
&NBSP; &NBSP; &NBSP;静态DataCache dtCache;
&NBSP; &NBSP; &NBSP; static void Main(string [] args)
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; servers = new List< DataCacheServerEndpoint>(1);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; servers.Add(cache_server);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; configuration.SecurityProperties = new DataCacheSecurity(DataCacheSecurityMode.None,DataCacheProtectionLevel.None);
$
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; configuration.Servers = servers;
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; configuration.NotificationProperties = new DataCacheNotificationProperties(1000,new TimeSpan(0,0,0,0,5));
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; configuration.LocalCacheProperties = new DataCacheLocalCacheProperties();
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; //禁用异常消息,因为此示例在缓存旁边工作
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; DataCacheClientLogManager.ChangeLogLevel(System.Diagnostics.TraceLevel.Info);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; DataCacheFactory CacheFactory = null;
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; CacheFactory = new DataCacheFactory(配置);
$
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; dtCache = CacheFactory.GetCache(" Rates");
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; DataCacheOperations allCacheOperations;
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; allCacheOperations = DataCacheOperations.AddItem |
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; DataCacheOperations.ReplaceItem
|
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; DataCacheOperations.RemoveItem;
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; DataCacheNotificationDescriptor dtnDesc2 = dtCache.AddItemLevelCallback(" Rates",allCacheOperations,myCacheLvlDelegate);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Console.WriteLine("准备接收通知");
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Console.Read();
&NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; public static void myCacheLvlDelegate(string myCacheName,
string myRegion,
string myKey,
DataCacheItemVersion itemVersion,
DataCacheOperations OperationId,
  ; DataCacheNotificationDescriptor nd)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; //显示一些代表参数
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Console.WriteLine("触发缓存级别通知!");
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Console.WriteLine(" Cache:" + myCacheName);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Console.WriteLine( Region:" + myRegion);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Console.WriteLine( Key:" + myKey);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Console.WriteLine( Operation:" + OperationId.ToString());
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Console.WriteLine();
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }
&NBSP; }
{
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 ?
问候
Alex
Alex
推荐答案
代码中有一个小错误。
DataCacheNotificationDescriptor dtnDesc2 = dtCache.AddItemLevelCallback(" Rates",allCacheOperations,myCacheLvlDelegate);
当你想要ItemLevel回调时,AddItemLevelCallback的第一个参数应该是"key"。您想要通知的(项目)[您在何处指定" cacheName"]。文档指针 -
)
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 useAddCacheLevelCallback - If you use this method you would get notification call backs for different operations as you specify in the method params.
希望差异很明显。
谢谢
Ranganath G
Ranganath G
这篇关于Appfabric缓存通知问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!