Hazelcast map listener with replay

可紊 提交于 2019-12-11 09:33:20

问题


I have multiple nodes participating in the Hazelcast cluster. One node receives events from an outside system and puts objects into an IMap. I have other nodes that need all of the entries in the map plus any new entries going forward. (For example, one use case for these secondary nodes is to present a live view of the data to a user).

One such approach would be:

map.addEntryListener(new MyListener());
for (Object value : map.values()) {
    ...
}

However, I may see the same object twice, if that object was added after my listener was invoked, but before my for loop. (Which isn't ideal, but I can make it work). I could also put the addEntryListener() after the for loop but then I could then miss entries.

Ideally, I would want an addEntryListenerWithReplay() method. I tried setting up an EntryListenerConfig before I start the HazelcastInstance, thinking that provided "add listener with replay" semantics, but my tests suggests otherwise.

The only other solution I can think of is using a distributed lock to make sure i don't miss any items inserted into the map.

Your suggestions and insights are very much appreciated, and many thanks to the Hazelcast team.

来源:https://stackoverflow.com/questions/29304623/hazelcast-map-listener-with-replay

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