Apache Geode cachelistener无法执行 [英] Apache geode cachelistener not executing

查看:135
本文介绍了Apache Geode cachelistener无法执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个新手问题,感谢您阅读.因此,我使用如下所示的复制区域启动了Geode服务器缓存过程:

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

和服务器进程

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

cache.xml定义了一个名为myRegion

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>

然后我使用.Net的Pivotal Native Client,在另一个过程中,我使用如下所示的缓存事件侦听器启动了客户端缓存:

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

MyEventHandler是:

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

,然后在第三步中,我再次为该进程创建另一个缓存,以将一些数据放入myRegion中.与没有侦听器的第二个过程的设置相同:

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

问题是在第三个进程将测试数据放入myRegion之后(我可以在服务器上看到它可以正常工作),第二个进程中的侦听器看不到它.我想念什么?

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?

谢谢...

推荐答案

在拥有监听器的客户端上,您需要

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.

这篇关于Apache Geode cachelistener无法执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆