package main
import (
"log"
"time"
"github.com/hashicorp/consul/api"
"github.com/pteich/clusterleader"
)
func main() {
config := api.DefaultConfig()
config.Address = "127.0.0.1:8500"
client, err := api.NewClient(config)
clusterLeader, err := clusterleader.NewClusterleader(client, "testkey", "localhost", 15*time.Second)
if err != nil {
log.Fatal(err)
}
go func() {
for err := range clusterLeader.Errors() {
log.Print(err)
}
}()
// as long as this loop runs we try to become leader
// an isElected event is send on every state change
// best would be to run this loop in a go routine and
// react to whatever we are leader or not
for isElected := range clusterLeader.Election() {
if isElected {
// we are leader
} else {
// not leader
}
}
}
-
Notifications
You must be signed in to change notification settings - Fork 0
⚖️Cluster Leader Election using Consul distributed locks
License
pteich/clusterleader
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
⚖️Cluster Leader Election using Consul distributed locks
Topics
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published