我使用以下方法连接到另一台机器上的Geode服务器:
CacheFactory cacheFactory = CacheFactory.CreateCacheFactory();
Cache c = cacheFactory
.AddServer("x.x.x.x", 40404)
.SetSubscriptionEnabled(true)
.Create();
RegionFactory regionFactory = c.CreateRegionFactory(RegionShortcut.CACHING_PROXY);
IRegion<string, string> r = regionFactory.Create<string, string>("r");
现在,如果我尝试输入一个条目,那么它就可以工作了。但是,如果我尝试通过使用以下方式订阅区域r中的事件:
r.GetSubscriptionService().RegisterAllKeys();
然后这抛出一个NotConnectedException
请问我错过了什么?谢谢…
我发现问题在于CacheFactory. create()在幕后设置了一个默认连接池,并且该默认池可能与服务器连接池不兼容。
因此,根据连接池代码必须设置一个池工厂并将其设置为接收订阅,例如:
CacheFactory cacheFactory = CacheFactory.CreateCacheFactory();
Cache c = cacheFactory.Create();
PoolFactory poolFactory = PoolManager
.CreateFactory()
.SetSubscriptionEnabled(true)
.AddLocator("x.x.x.x", 10334);
Pool pool = null;
if (PoolManager.Find("myPool") == null)
pool = poolFactory.Create("myPool");
int loadConditInterval = pool.LoadConditioningInterval;
RegionFactory regionFactory = c.CreateRegionFactory(RegionShortcut.CACHING_PROXY);
IRegion<string, string> r = regionFactory.SetPoolName("myPool").Create<string, string>("r");
r.GetSubscriptionService().RegisterAllKeys();
r.AttributesMutator.SetCacheListener(new MyListener<string, string>());
其中MyListener根据事件处理处理事件订阅