Search code examples
javaeventsignite

Java Apache Ignite event listner unexpected behavior


I have playing with Ignite Microservice example https://github.com/dmagda/MicroServicesExample. I added an event listner, and explicitly subscribed for a specific cache

data-node-config.xml:

<bean class="org.apache.ignite.configuration.IgniteConfiguration">

    <property name="includeEventTypes">
        <util:constant static-field="org.apache.ignite.events.EventType.EVTS_CACHE"/>
    </property>

DataNodeStartup.java:

ignite.events(ignite.cluster().forCacheNodes("vehicles")).remoteListen(locLsnr, rmtLsnr,
        EVT_CACHE_OBJECT_PUT, EVT_CACHE_OBJECT_READ, EVT_CACHE_OBJECT_REMOVED);

But i always have catched unexpected event for another cache "maitenance".

Does the forCacheNodes("vehicles") not work or is my wrong config?

UPDATED:

I'am listening events like this

        IgnitePredicate<CacheEvent> rmtLsnr = new IgnitePredicate<CacheEvent>() {
        @Override
        public boolean apply(CacheEvent evt) {

            System.out.println("Cache event [name=" + evt.name() + ", newValue : " + evt.newValue() + "]");
            return true;
        }
    };

Solution

  • That's expected behaviour. If you want to listen for events from a specific cache, you can do that in your remote filter.

    Your listener doesn't just listen to events for a specific cache. It listens to all events of the specified type from the nodes where your cache is located, which is not quite the same thing.