🪅 Distributed consistent process registry over consul cluster 🪅
Go to file
2023-08-30 12:45:07 +03:00
.github/workflows Bump CI (#8) 2023-06-13 19:28:51 +05:00
config Add Consul based discovery service (#11) 2019-03-18 16:52:51 +03:00
src TD-704: Adds consuela_registry_server test operation (#11) 2023-08-30 12:45:07 +03:00
test TD-704: Adds consuela_registry_server test operation (#11) 2023-08-30 12:45:07 +03:00
.env OPS-52: Support Consul 1.7+ (#2) 2022-04-11 11:33:31 +03:00
.gitignore OPS-52: Introduce CI workflow w/ GH Actions (#1) 2022-04-08 23:36:43 +03:00
.gitmodules Drop proprietary CI stuff 2022-04-08 15:04:37 +03:00
compose.yml OPS-52: Introduce CI workflow w/ GH Actions (#1) 2022-04-08 23:36:43 +03:00
Dockerfile.dev OPS-52: Introduce CI workflow w/ GH Actions (#1) 2022-04-08 23:36:43 +03:00
elvis.config OPS-52: Introduce CI workflow w/ GH Actions (#1) 2022-04-08 23:36:43 +03:00
LICENSE Fix authorship in the copyright related license appendix (#7) 2019-02-28 16:07:16 +03:00
Makefile OPS-52: Introduce CI workflow w/ GH Actions (#1) 2022-04-08 23:36:43 +03:00
README.md Point to more relevant Consul issue (#36) 2019-11-20 19:52:57 +03:00
rebar.config OPS-52: Introduce CI workflow w/ GH Actions (#1) 2022-04-08 23:36:43 +03:00
rebar.lock OPS-52: Introduce CI workflow w/ GH Actions (#1) 2022-04-08 23:36:43 +03:00

consuela

Distributed consistent process registry over consul cluster.

Build

$ rebar3 compile

Use

As process registry

As any other process registry, you can register and refer to a process with {via, consuela, Name} tuple:

{ok, Pid} = gen_server:start_link({via, consuela, some_global_resource}, ?MODULE, Args, []).

To set things up you can start consuela with registry configured like this:

{consuela, [
    {registry, #{
        nodename => "consul",
        namespace => <<"my-service-ns">>,
    }}
}

Complete registry configuration looks like this:

#{
    % [Required] Where's Consul server in the network?
    nodename => "consul0",
    % [Required] What namespace to use to isolate my set of registrations?
    namespace => <<"my-service-ns">>,
    % Consul client options
    consul => #{
        % Consul API endpoint ("http://{nodename}:8500" by default)
        url => "http://consul0:8500",
        opts => #{
            % Client event handler, e.g. for logging communication issues
            pulse => {my_service_logger, client}
        }
    },
    % Consul session options
    % See: https://www.consul.io/docs/internals/sessions.html
    session => #{
        % Name of the session ("{namespace}" by default)
        name => <<"my-service-session">>,
        % How long should session stay alive in Consul without renewing? (20s by default)
        ttl => 20,
        % How long should Consul prevent locks left after died session to be re-acquired? (10s by default)
        lock_delay => 10
    },
    % Session keeper options
    keeper => #{
        % How often session should be renewed? Number of seconds or ratio (half of TTL by default)
        interval => genlib_rational:new(1, 3),
        % Keeper event handler, e.g. for logging renewal issues
        pulse => {my_service_logger, keeper}
    },
    reaper => #{
        % For how long and How often to retry failed reaping? (at most 10min with 5s intervals between attempts by default)
        retry => genlib_retry:linear({max_total_timeout, 10 * 60 * 1000}, 5000),
        % Reaper event handler, e.g. for tracking queue metrics
        pulse => {my_service_logger, reaper}
    },
    registry => #{
        % Registry event handler, e.g. for logging failed registrations or measuring registration latencies
        pulse => {my_service_logger, registry}
    }
}

Gotchas

Roadmap

  • User-friendly lock identifiers? E.g. space/acceptor-10.