Time Based Eviction in Hazelcast

我们两清 提交于 2019-12-11 14:09:31

问题


I am working on a requirement where i'd have N hazelcast instances running in a cluster and also have kafka consumers running on all of them.

Now the ask is, each message that comes in on kafka, should be added to the distributed map and the entry must be evicted every 20 seconds, which i did by using a combination of time to live and max-idle seconds parameters in the map config.

But what i really want is that when the entry is evicted, only one of the nodes should process it, right now, the entry eviction is being informed to all the nodes.

Let me know if any more information is needed.


回答1:


You have to add a localEntryListener to your distributed map so that a member will only receive notifications for which it is an owner.

e.g.

if(map != null){
            map.addLocalEntryListener(new EntryAddedListener<Long, Long>() {
                @Override
                public void entryAdded(EntryEvent<Long, Long> event) {
                    log.info("LOCAL ENTRY ADDED : {} at {}", event, System.currentTimeMillis());
                }
            });

The above example is for the EntryAddedListener, you can similarly implement a EntryEvictedListener as well.



来源:https://stackoverflow.com/questions/47274007/time-based-eviction-in-hazelcast

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