🎄 Happy Holidays! 🥳
Most of Solace is closed December 24–January 1 so our employees can spend time with their families. We will re-open Thursday, January 2, 2024. Please expect slower response times during this period and open a support ticket for anything needing immediate assistance.
Happy Holidays!
Please note: most of Solace is closed December 25–January 2, and will re-open Tuesday, January 3, 2023.
Use exclusive queue as distributed lock?
I was wondering if I could use an exclusive queue as a rudimentary distributed "headship" mechanism. If there are multiple queue consumers that create a flow to the queue, my thought is that whoever is the active consumer would considered the head node, and if they shut down then headship would automatically be transferred to a different node. Is there any way via JCSMP for a consumer to know if a flow is active or passive?
Comments
-
Just thought of an additional way to implement this with an exclusive queue, without needing to know explicitly that you're active or passive. If I prepopulate the queue with a single message, and each connected consumer creates a flow but never acks any messages, then receiving that message would indicate that you're the active consumer. If the active (head) consumer shuts down then another consumer will become active and receive that same message, indicating that it's the head and can perform headship tasks. Does that sounds reasonable?
0 -
There is an activeFlowIndication for a consumer to determine (or set) the state of the flow.
0 -
Hey @petegehrman, interesting thoughts for sure! As @amackenzie mentioned we do have the concept of ActiveFlowIndication that allows a consumer to know the state of their flow.
Are you essentially thinking about using this as a mechanism for leader election across multiple apps? If so I'd suggest checking out what @GreenRover contributed to the SolaceCommunity. He created the Spring Solace Leader Election project which allows for leader election for spring integration using Solace exclusive queues . He also took the time to create some great docs and covered a few use cases that the project might be useful.
1 -
@petegehrman yes, this is a super useful pattern in Solace, essentially a network mutex. We use this heavily in various production scenarios where you want to ensure only one active participant... e.g. HA publishers: have multiple publishers available to publish some stream of data onto Solace, but only the guy who has the ACTIVE_FLOW_NOTIFICATION from their shared exclusive queue is the live publisher. (they're only using the queue to determine who's active, not subscribing to anything).
Just did some Googling, and I'm surprised that I don't see a Solace blog about this well-known pattern. Huh! Maybe one of us should go write one..! 🙃
2 -
Cool, thanks everyone for the information. I guess I was on the right track with the idea, but I missed the documentation on the FlowEventHandler. This is going to be very useful for us!
2