Geode 本机客户端 RegisterAllKeys 产生 NotConnectedException

Geode native client RegisterAllKeys produces NotConnectedException

我使用以下方法连接到另一台机器上的 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() 在后台设置默认连接池有关,而该默认连接池可能与服务器连接池不兼容。

所以根据 connection pool code 必须设置一个池工厂并将其设置为接收订阅,例如:

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根据event handling

处理事件订阅