Skip to content

dpires/consul-leader-election

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

consul-leader-election

Build Status Coverage Status

An implementation of Consul leader election based on https://www.consul.io/docs/guides/leader-election.html

Usage

import (
	"github.com/dpires/consul-leader-election"
	"github.com/dpires/consul-leader-election/client"
	"github.com/hashicorp/consul/api"
)

config := api.DefaultConfig()                                  // Create a new api client config
consulclient, _ := api.NewClient(config)                       // Create a Consul api client

leaderElection := &election.LeaderElection{
        StopElection:  make(chan bool),                        // The channel for stopping the election
        LeaderKey:     "service/my-leadership-service/leader", // The leadership key to create/aquire
        WatchWaitTime: 10,                                     // Time in seconds to check for leadership
        Client: &client.ConsulClient{Client:consulclient},     // The injected Consul api client
}

go leaderElection.ElectLeader()                                // Run the election

About

Consul leader election implementation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages