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