Apache Ignite Event Listener does not receive remote events when i setClientMode=true

霸气de小男生 提交于 2019-12-24 00:56:10

问题


Please see the below event listener code.

Client Node attempting to be a listener:

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

Server Node hosting a 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);

A remote client updating the cache:

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

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 ?


回答1:


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.

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



来源:https://stackoverflow.com/questions/38889790/apache-ignite-event-listener-does-not-receive-remote-events-when-i-setclientmode

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!