Hazelcast中基于时间的逐出 [英] Time Based Eviction in Hazelcast

查看:117
本文介绍了Hazelcast中基于时间的逐出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在满足一个要求,即我需要在群集中运行N个hazelcast实例,并且在所有实例上都需要kafka使用者.

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.

现在要问的是,kafka上出现的每条消息都应添加到分布式地图,并且条目必须每20秒逐出一次,这是我通过结合使用生存时间和max-idle seconds参数来完成的在地图配置中.

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.

推荐答案

您必须将localEntryListener添加到您的分布式地图中,以便成员将仅收到其所有者的通知.

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

例如

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());
                }
            });

上面的示例用于EntryAddedListener,您也可以类似地实现EntryEvictedListener.

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

这篇关于Hazelcast中基于时间的逐出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆