- My application needs to subscribe to a large number of "topics" via a pub-sub message service.
- All "topic" names are stored as keys in a Hazelcast IMap distributed cache (with related info as values).
- When multiple instances of my application are running, I want them to split the "topics" evenly among their local caches, and subscribe/unsubscribe from the topics when these local caches are updated. E.g:
- Instance 1 starts, subscribes to all the keys
- Instance 2 starts and subscribes to half of the keys, instance 1 unsubscribes from these same keys.
- Instance 1 goes down. Instance 2 subscribes to all the keys which instance 1 had. i.e I expect all topics in cache to be subscribed to by exactly 1 instance at a given time.
Which Hazelcast Event Listener should I use for my application, such that I can listen for repartition AND restoring-from-backup events?
I have tried the following but have had issues with all implementations:
MembershipListener + CountDownLatch + Comparing keys in localKeySet before & after "ClusterReadyCountDown" to subscribe/unsubscribe: this was my initial implementation, but my application is facing some serious bugs in production related to missing/duplicate subscriptions across multiple instances. I think the MembershipListener is called before redistribution occurs, so subscribing/unsubscribing messes up sometimes. Suggestions are welcome!
LocalEventListener: it only triggers when I explicitly do map.put()/remove(), it doesn't trigger on cache repartition/restore from backup, only on programmatic operations on the IMap
MigrationListener: it only triggers when a node joins or leaves "gracefully", it doesn't trigger when a node leaves "ungracefully".
Please let me know if you need more information!
P.S, I've already seen this thread, which suggests the MigrationListener -- but it didn't work in my use case.