Search code examples
javaeventscachingignite

Apache ignite single cache(map) event registration for cache event


I am looking for a way to register single cache's cache event with ignite.

It is possible to register all put events of ignite envoriment with this code;

        IgniteBiPredicate<UUID, CacheEvent> lsnr = new IgniteBiPredicate<UUID, CacheEvent>() {
                @Override public boolean apply(UUID uuid, CacheEvent evt) {
                    System.out.println("Received event [evt=" + evt.name() + ", key=" + evt.key() +
                        ", oldVal=" + evt.oldValue() + ", newVal=" + evt.newValue());

                    return true; // Continue listening.
                }
            };
    ignite.events().localListen(lsnr, EventType.EVT_CACHE_OBJECT_PUT);

But i would like to register only cache event for specific map(cache) because of performance reasons. Otherwise, i will have to check cache name for each event, which could cause huge load on system with a high number of transactions.

Thanks for any help and guidance.


Solution

  • If you want to listen to data updates, continuous queries are better option: https://apacheignite.readme.io/docs/continuous-queries

    This feature works on per-cache level, supports proper event ordering and guarantees delivery in case of topology changes.