anchor.diff:  %%
   ttl_string(Value) ->
     list_to_atom(integer_to_list(Value) ++ "s").
  +
  +
  +%% @private
  +%% @spec log(Module, Function, Message, Args) -> ok
  +%% @doc Ensure all logged lines share the same format
  +%% @end
  +%%
  +log(Module, Fun, Message, Args) ->
  +  Module:Fun(string:join(["autocluster_consul: ", Message, "~n"], ""), Args).
  +
  +%% Logging methods
  +
  +debug(Message) -> log(rabbit_log, debug, Message, []).
  +debug(Message, Args) -> log(rabbit_log, debug, Message, Args).
  +info(Message) -> log(rabbit_log, info, Message, []).
  +info(Message, Args) -> log(rabbit_log, info, Message, Args).
  +err(Message) -> log(rabbit_log, error, Message, []).
  +err(Message, Args) -> log(rabbit_log, error, Message, Args).
  +warning(Message) -> log(rabbit_log, error, Message, []).
  +warning(Message, Args) -> log(rabbit_log, error, Message, Args).
  
positive.code: 
  
  %% @private
  %% @spec join_cluster(term()) -> ok
  %% @doc Have the current node join a cluster using the specified discovery node
  %% @end
  %%
  join_cluster([]) -> ok;
  join_cluster(Nodes) ->
    io:format("              Joining existing cluster.~n~n"),
    application:stop(rabbit),
    mnesia:stop(),
    rabbit_mnesia:reset(),
    rabbit_mnesia:join_cluster(lists:nth(1, Nodes), disc),
    mnesia:start(),
    rabbit:start(),
    ok.
  
  
  %% @private
  
negative.code: %% @end
  %%
  shutdown() ->
    case unregister() of
      ok             -> info("Unregistered");
      {error, Error} -> err("Error unregistering: ~p", [Error])
    end.
  
  
  %% @private
  %% @spec join_cluster(term()) -> ok
  %% @doc Have the current node join a cluster using the specified discovery node
  %% @end
  %%
  join_cluster([]) ->
    debug("No nodes in existing cluster"),
    ok;
  join_cluster(Nodes) ->
    debug("Joining existing cluster: ~p", [Nodes]),
    application:stop(rabbit),
    mnesia:stop(),
    rabbit_mnesia:reset(),
    rabbit_mnesia:join_cluster(lists:nth(1, Nodes), disc),
    mnesia:start(),
    rabbit:start(),
    info("Cluster joined"),
    ok.
  
  
  %% @private
  %% @spec maybe_register() -> ok|error
  %% @doc Register with Consul and join the cluster if needed
  %% @end
  %%
  maybe_register() ->
    Nodes = cluster_nodes(),
    case lists:member(node(), Nodes) of
      true ->
        debug("Node is already registered"),
        ok;
      false ->
        case register() of
          ok ->
            join_cluster(Nodes);
          {error, 400}   ->
            err("Permission denied when registering node with Consul"),
            error;
          {error, Error} ->
            err("Error registering: ~p", [Error]),
            error
      end
    end.
  
  
  %% @private
  %% @spec register() -> mixed
  %% @doc Register with Consul as providing rabbitmq service
  %% @end
  %%
  register() ->
    info("Registering node with Consul"),
    case autocluster_consul_client:post([agent, service, register], registration_body()) of
      ok -> ok;
      Error -> Error
    end.
  
  
  %% @private
  %% @spec unregister() -> mixed
  %% @doc Deregister the rabbitmq service for this node from Consul
  %% @end
  %%
  unregister() ->
    info("Unregistering node with Consul"),
    case autocluster_consul_client:get([agent, service, deregister, autocluster_consul_config:service()], []) of
      {ok, _} -> ok;
      Error -> Error
    end.
  
  
  %% @private
  %% @spec cluster_nodes() -> list()
  %% @doc Fetch the list of cluster nodes from Consul, returning them as a list of
  %%      atoms.
  %% @end
  