Geode native client RegisterAllKeys produces NotConnectedException

99 views Asked by At

I connect to a Geode server on another machine using:

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");

Now if I try and put an entry then it works. However, if I try and subscribe to events in region r by using:

r.GetSubscriptionService().RegisterAllKeys();

then this throws a NotConnectedException

What am I missing here please? Thanks...

1

There are 1 answers

0
rupweb On BEST ANSWER

I found that the problem was to do with the CacheFactory.create() setting up a default connection pool behind the scenes, and that default pool may not be compatible with the server connection pool.

So according with connection pool code have to setup a pool factory and set that to receive subscriptions, like:

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>());

where MyListener handles the event subscription according to event handling