防止hazelcast在每个节点上注册EvictionListener [英] Prevent hazelcast to register EvictionListener on every node

查看:255
本文介绍了防止hazelcast在每个节点上注册EvictionListener的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们当前遇到一个问题,即我们在Hazelcast Config Bean中为特定地图配置地图条目侦听器.我们的问题是,在每个节点上都实例化了侦听器,这对我们的实现有意义并正确,但实际上并非我们试图实现的目标.有没有一种方法可以只在一个地图上为一个群集节点或群集本身添加一个侦听器,以便在驱逐该条目时仅向该地图注册一个侦听器?

We currently having an issue that we configure a map entry listener for a specific map in the Hazelcast Config Bean. The problem we have is that the listener is instanciated on every node what make sense and is right with our implementation but actually it is not what we try to achieve. Is there a way to just add a listener on a map for just one cluster node or the cluster itself so when the entry is evicted there is only one listener registered to the map?

要清楚:有12台运行我们的Spring Boot应用程序的服务器都注册为hazelcast集群中的节点.因此,如果逐出一个条目,则有12个侦听器对逐出做出反应.我们只想为这种情况注册一个侦听器.

To be clear: There are 12 Servers running our spring boot application which are all registered as nodes in the hazelcast cluster. So if an entry is evicted there are 12 listeners which react to the eviction. We just want to register one listener for this case.

这是来自Config Bean的代码,该代码在我们服务器集群中所有节点的所有应用程序中运行:

This is the code from the Config Bean which is run in every application in our server cluster which are all nodes:

@Bean
Config hazelcastConfig(AppConfigurationProperties properties, 
HazelcastEvictionListener hazelcastEvictionListener) {

HazelcastProperties hazelcastProperties = properties.getHazelcast();
    Config config = new Config();

    MapConfig activationMapConfig = new MapConfig();
    activationMapConfig.setName(HazelcastMaps.ACTIVATION_INFORMATION);
    activationMapConfig.addEntryListenerConfig(new 
EntryListenerConfig(hazelcastEvictionListener, false, true));
...}

是否有一种方法可以配置hazelcast,以便此EntryListener在所有节点上仅注册一次?

Is there a way to configure hazelcast so this EntryListener is only registered once over all nodes?

我真的不知道是否以这种方式使用hazelcast是否有意义,但是我是Hazelcast主题的新手,希望获得帮助或想法.

I actually have no Idea if this even makes sense to use hazelcast this way but I'm new to the Hazelcast topic and hope for help or ideas.

推荐答案

对我来说,解决方案是设置标志local = true,因此在集群中,只有一个成员在其本地地图存储区中保存该值.这只会触发持有此值的特定成员上的EvictionListener,这只会导致一个事件.

For me the solution was to set the flag local=true so in the cluster there is only one member holding the value in its local map store. This triggered only the EvictionListener on this specific member holding this value which result in only one event.

这篇关于防止hazelcast在每个节点上注册EvictionListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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