Q:

Advice about Jms publish subscriber model

We have an application deployed on prod in a multicluster enviroment, with a load balancer. 
In the application, we keep a cache to improve performance. 
The problem is that as we are in a multicluster environment, a singleton is not really a singleton, so if we clear the cache in one node, the other node isn't notified to clean his own cache. 
We currently only have two nodes but we could add more in the future. So my first thought was to implement a JMS queue with the model  publish/subscriber. Once a node needs to clear his cache, it would send a message to the queue, and all the nodes(even himself) should be notified automatically to clear their caches. I've checking with activemq, but as far I've seen, once the publisher sends a message, the subscriber need to do getMessage() to receive the message. That would imply that we should be pulling continously the queue to see if there is any message there, and also I would have to ensure that once all the subscribers have read the message, the message is removed.
I'm writing just to get some advice on how to implement such a thing, if activemq or any other jms implementation provides something that would fit our needs.
Thank you  

A:

This scenario is pretty simple with all JMS providers, including ActiveMQ.
Simply publish a message to a topic, say CLEAR.CACHE. Then have each node connect with a client ID unique to that node (the same ID even after a restart, so you need to fetch that ID from environment/configuration - not code).
Each node is then able to create a durable subscriber to the CLEAR.CACHE topic. A copy will be delivered to each node - even if the node is offline during the publication.
Some official docs: https://docs.oracle.com/cd/E19798-01/821-1841/bncgd/index.html
Just wanted to say that there are complete distributed cache solutions to use as well, where you don't have to manually deal with this stuff. Redis, hazlecast etc.. But if all you want is a basic "clear cache" command between nodes (or any other type of command to distribute among nodes), then JMS is the way to go.

