当我setClientMode = true时,Apache Ignite事件侦听器不接收远程事件 [英] Apache Ignite Event Listener does not receive remote events when i setClientMode=true

查看:89
本文介绍了当我setClientMode = true时,Apache Ignite事件侦听器不接收远程事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请参阅下面的事件侦听器代码.

Please see the below event listener code.

尝试成为侦听器的客户端节点:

Ignition.setClientMode(true);
IgniteConfiguration cfg = new IgniteConfiguration();
TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder();
ipFinder.setAddresses(Arrays.asList("127.0.0.1", "127.0.0.1:47500..47509"));
TcpDiscoverySpi spi = new TcpDiscoverySpi();
spi.setIpFinder(ipFinder);
cfg.setDiscoverySpi(spi);
cfg.setIncludeEventTypes(EventType.EVTS_CACHE);
IgnitePredicate<CacheEvent> rmtLsnr = (CacheEvent cacheEvent) -> {

if(cacheEvent.type() == EventType.EVT_CACHE_OBJECT_PUT) {
System.out.println(cacheEvent.name() + "," + cacheEvent.key());

}
            return true;
 };
Ignite ignite = Ignition.start(cfg);
ignite.events(ignite.cluster()
                .forCacheNodes(TestConstants.IgniteEventsTest.ORDER_CACHE))
                .remoteListen(null,rmtLsnr,EventType.EVTS_CACHE);

托管缓存的服务器节点:

IgniteConfiguration cfg = new IgniteConfiguration();

TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder();

ipFinder.setAddresses(Arrays.asList("127.0.0.1", "127.0.0.1:47500..47509"));

TcpDiscoverySpi spi = new TcpDiscoverySpi();

spi.setIpFinder(ipFinder);

cfg.setDiscoverySpi(spi);

Ignite ignite = Ignition.start(cfg);
CacheConfiguration cacheCfg = new CacheConfiguration(TestConstants.IgniteEventsTest.ORDER_CACHE);
cacheCfg.setCacheMode(CacheMode.PARTITIONED);
cacheCfg.setWriteSynchronizationMode(FULL_ASYNC);
cacheCfg.setBackups(1);

远程客户端更新缓存:

Ignition.setClientMode(true);
IgniteConfiguration cfg = new IgniteConfiguration();
TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder();
ipFinder.setAddresses(Arrays.asList("127.0.0.1", "127.0.0.1:47500..47509"));
TcpDiscoverySpi spi = new TcpDiscoverySpi();
spi.setIpFinder(ipFinder);
cfg.setDiscoverySpi(spi);

Ignite ignite = Ignition.start(cfg);
CacheConfiguration cacheCfg = new CacheConfiguration(TestConstants.IgniteEventsTest.ORDER_CACHE);
cacheCfg.setCacheMode(CacheMode.PARTITIONED);
cacheCfg.setWriteSynchronizationMode(FULL_SYNC);
IgniteCache<Integer, Order> 
clientOrderCache  = ignite.getOrCreateCache(cacheCfg);

in a loop...

clientOrderCache.put(key , order);

我的观察是,当事件侦听器上的ClientMode = true时,我们不接收事件.请让我知道事件侦听器是否必须在服务器模式下侦听事件吗?还是我做错什么了?

My observation is that when ClientMode=true on the event listener we dont receive events. Please let me know if its mandatory for an event listener to be in server mode to listen for events? Or is it something wrong i am doing ?

推荐答案

您未定义本地侦听器(代码中为 null ).远程筛选器总是在触发事件的地方执行,如果进行高速缓存更新,它是服务器节点之一.如果还创建本地侦听器,则所有远程筛选器返回 true 的事件都将传播到客户端.

You did not define the local listener (it's null in your code). Remote filter is always executed where the event was fired, in case of cache update it's one of the server nodes. If you create a local listener as well, all events for which remote filter returns true will be propagated to the client.

有关代码示例,请参见CacheEventsExample [1].

Refer to the CacheEventsExample [1] for the code sample.

[1] https://github.com/apache/ignite/blob/master/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheEventsExample.java

这篇关于当我setClientMode = true时,Apache Ignite事件侦听器不接收远程事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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