Class: Consul::Client::V1

Inherits:
Object
  • Object
show all
Defined in:
lib/consul/client.rb

Overview

Do not instantiate this class directly.

See Also:

Instance Method Summary collapse

Instance Method Details

#http(host: "localhost", port: 8500, logger: NULL_LOGGER) ⇒ Consul::Client::HTTP

Returns a thin wrapper around the Consult HTTP API.

Examples:

http = Consul::Client.v1.http(logger: Logger.new($stdout))
puts http.get("/get/self")["Member"]["Name"]

Parameters:

  • host (String) (defaults to: "localhost")

    host of Consul agent.

  • port (Integer) (defaults to: 8500)

    port to connect to Consul agent.

  • logger (Logger) (defaults to: NULL_LOGGER)

    logger for diagnostic information.

Returns:



56
57
58
# File 'lib/consul/client.rb', line 56

def http(host: "localhost", port: 8500, logger: NULL_LOGGER)
  HTTP.new(host: host, port: port, logger: logger)
end

#local_service(name, http: Consul::Client.v1.http(), logger: http.logger) ⇒ Consul::Client::LocalService

Returns high-level local service utility functions.

Examples:

local = Consul::Client.v1.local_service('web')
local.coordinated_shutdown! { $healthy = false }

Parameters:

  • name (String)

    name of the service. Must match service ID in Consul.

  • http (Consul::Client::HTTP) (defaults to: Consul::Client.v1.http())

    http client to use.

  • logger (Logger) (defaults to: http.logger)

    logger for diagnostic information.

Returns:



34
35
36
# File 'lib/consul/client.rb', line 34

def local_service(name, http:Consul::Client.v1.http(), logger:http.logger)
  LocalService.new(name, http: http, logger: logger)
end

#service(*args) ⇒ Object

Returns high-level service utility functions.

Examples:

service = Consul::Client.v1.service('web')
service.lock('leader') { puts "I am the cluster leader!" }


43
44
45
# File 'lib/consul/client.rb', line 43

def service(*args)
  Service.new(*args)
end