Using MapLoader for a Distributed Hazelcast Card Inside a Client

I rate Hazelcast as a distributed data grid solution for the application I'm working on. Hazelcast is configured for a distributed cluster, and my application uses Spring to define the Hazelcast client this way:

<hz:client id="hazelcastClient" group-name="dev" group-password="dev-pass"> <hz:member>localhost:5701</hz:member> </hz:client> 

In my Hazelcast node, in the hazelcast.xml file hazelcast.xml I configured a map with all the necessary configuration. Let them say that this mapping is called myMap . I see that this card is configured correctly when using the Hazelcast web application for monitoring (mancenter).

Now I need to configure the card for input to my bean from the application side. If I do something like

 <hz:map id="myMap" instance-ref="hazelcastClient" name="myMap" /> 

And I insert this card into my bean, which contains the sampling logic, I have no problem.

However, I also wrote a class that implements the MapLoader interface to handle missing cache data. My problem is that I donโ€™t know how to associate this MapLoader with the cache I specified. If I try something like

 <hz:map id="myMap" instance-ref="hazelcastClient" name="myMap"> <hz:map-store enabled="true" implementation="myMapLoader"/> </hz:map> 

I get an XML parsing error, because it seems that when hz:map used as a top-level element (and not inside hz:config , for example), you cannot specify internal elements. This makes me think that you need to define the hz:config element. But this is not very clear from the documentation if you can define the hz:config element for the client. It seems to me that you need to use hz:config if you want your application to be part of a cluster. I am not sure, however, if he logically fixed that my application should be part of a cluster - it is basically a data mesh client.

Do you have any thoughts on how to configure the application to achieve the desired behavior?

Thanks!

+4
source share
1 answer

You cannot configure the card on the client side. You must configure myMap and MapLoader/MapStore on the Hazelcast node. MapStore / MapLoader operations are performed by the Hazelcast node, which owns the data, not the client.

Hazelcast Node

 <hz:config> ... <hz:map name="myMap" backup-count="1" max-size="0"> <hz:map-store enabled="true" implementation="myMapLoader" /> </hz:map> ... </hz:config> 

-OR- using hazelcast.xml

 <map name="myMap"> <backup-count>1</backup-count> <time-to-live-seconds>0</time-to-live-seconds> <max-idle-seconds>0</max-idle-seconds> <map-store enabled="true"> <class-name>foo.bar.MyMapLoader</class-name> <write-delay-seconds>0</write-delay-seconds> </map-store> </map> 

On the client side, just create an instance of myMap ;

 <hz:map id="myMap" instance-ref="hazelcastClient" name="myMap" /> 

When a client puts / receives from this card, node processes the clientโ€™s request, MapLoader / MapStore is called.

+13
source

Source: https://habr.com/ru/post/1412606/


All Articles