Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handle Leader instance with Spring Boot and Consul [closed]

I'm currently working on a spring boot application that uses Consul as a service discovery.
Our web API has multiple instances on different Docker containers and is registered successfully with Consul.
Our main issue now is to elect a leader among our instances and have an automatic re-election in case if the former leader is down.
I have read that Consul provides a Key-Value Store and has lock on those, I was thinking that we could use a key created before hand, then the first instance to read it would have the "lock". If this instance crashes, an other one would acquire the lock and would be detected as the new leader.
I have read several examples, however I've only found command lines examples, not Java/Spring boot implementations.

Can anyone tell me if this idea could do the job and could anyone provide an example with Spring Boot or give me a link to a tutorial please?
I'm a total beginner with Spring Boot and Consul.

Thanks in advance!

like image 910
Barney Stinson Avatar asked Oct 29 '22 23:10

Barney Stinson


1 Answers

Have a look at java library for consul leader election,which has cooked methods for session creation,leader election etc.

https://github.com/advantageous/elekt-consul

like image 88
Shivakumar NH Avatar answered Nov 09 '22 08:11

Shivakumar NH