问题
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