Search code examples
gemfiregeode

Apache geode cachelistener not executing


This is a newbie question, thanks for reading it. So I start a Geode server cache process with a replicated region like this:

gfsh>start locator --name=myLocator

and a server process

start server --cache-xml-file=D:\Geode\config\cache.xml --name=myGeode --locators=localhost[10334]

The cache.xml defined a replicated region called myRegion

<?xml version="1.0" encoding="UTF-8"?>
<cache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns="http://geode.apache.org/schema/cache" 
    xsi:schemaLocation="http://geode.apache.org/schema/cache http://geode.apache.org/schema/cache/cache-1.0.xsd" 
    version="1.0">
<cache-server/>
<region name="myRegion" refid="REPLICATE"/>
</cache>

and then I am using the Pivotal Native Client for .Net with which in another process I start up a client cache with a cache event listener as follows:

CacheFactory cacheFactory = CacheFactory.CreateCacheFactory();
Cache cache = cacheFactory.SetSubscriptionEnabled(true).Create();
RegionFactory regionFactory = cache.CreateRegionFactory(RegionShortcut.CACHING_PROXY);
IRegion<string, string> region = regionFactory.Create<string, string>("myRegion");
region.AttributesMutator.SetCacheListener(new MyEventHandler<string, string>());

The MyEventHandler is:

public class MyEventHandler<TKey, TVal> : ICacheListener<TKey, TVal>
{
    public void AfterCreate(EntryEvent<TKey, TVal> ev)
    {
        Console.WriteLine("Received AfterCreate event for: {0}", ev.Key.ToString());
    }
...
}

and then again in a third process I create another cache for that process to put some data into myRegion. It's the same setup as the second process without the listener:

CacheFactory cacheFactory = CacheFactory.CreateCacheFactory();
Cache cache = cacheFactory.SetSubscriptionEnabled(true).Create();
RegionFactory regionFactory = cache.CreateRegionFactory(RegionShortcut.CACHING_PROXY);
IRegion<string, string> region = regionFactory.Create<string, string>("myRegion");
region["testKey"] = "testValue";

The problem is after the third process puts the test data into myRegion (that I can see on the server so that's working) the listener in the second process doesn't see it. What am I missing?

Thanks...


Solution

  • On the client where you have the listener, you need to register interest in either all or a subset of key so that the server knows to send updates to the client.