Prevent hazelcast to register EvictionListener on every node

旧城冷巷雨未停 提交于 2020-01-24 21:04:06

问题


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?

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.

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

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

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.


回答1:


The listener registration is done on a per client basis which means you can register on one client and not another; however, it sounds like you want a cluster wide singleton. To achieve a cluster wide singleton you can use a Hazelcast distributed lock for the client/bean is optionally acquired, so there is only one method call can be executed in a particular cluster at-a-time, so no data corruption / race conditions are possible.




回答2:


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.



来源:https://stackoverflow.com/questions/58115233/prevent-hazelcast-to-register-evictionlistener-on-every-node

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