Sign in

    moonbitstack/moonzero/consul does not have a README file

    ConsulHttp

    pub(open) trait ConsulHttp {
    fn request(Self, String, String, Bytes) -> ConsulResponse raise
    }

    A transport to a consul agent: it performs one HTTP request (method and path, with body for writes) and returns the response. Implementations own the medium — a real HTTP socket, or an in-memory fake.

    ConsulError

    pub suberror ConsulError {
    ConsulError(String)
    }

    A consul API call that failed — a transport error, or a non-2xx agent response.

    ConsulClient

    pub struct ConsulClient {
    http : &ConsulHttp
    }

    A consul client over a ConsulHttp, exposing the agent operations discovery uses.

    ConsulClient::agent_services

    fn ConsulClient::agent_services(self : ConsulClient) -> Array[(String, String)] raise ConsulError

    GET /v1/agent/services: every service instance registered on this agent, as (instance-id, service-name) pairs — the list a by-name deregister filters to find the ids to drop.

    ConsulClient::check_pass

    fn ConsulClient::check_pass(self : ConsulClient, service_id : String) -> Unit raise ConsulError

    PUT /v1/agent/check/pass/service:<id>: mark an instance's TTL check passing, the keep-alive that renews its lease.

    ConsulClient::deregister_service

    fn ConsulClient::deregister_service(self : ConsulClient, id : String) -> Unit raise ConsulError

    PUT /v1/agent/service/deregister/<id>: deregister one instance.

    ConsulClient::health_service

    GET /v1/health/service/<name>?passing=true: the healthy instances of name, each as its Service.Address:Service.Port endpoint (falling back to Node.Address when the service advertises no address of its own, as consul's clients do).

    ConsulClient::new

    A client over http.

    ConsulClient::register_service

    fn ConsulClient::register_service(self : ConsulClient, id : String, name : String, address : String, port : Int, ttl_secs : Int) -> Unit raise ConsulError

    PUT /v1/agent/service/register: register an instance under name at address:port with an id, held alive by a TTL check that consul deregisters ttl*3 seconds after it stops passing. Pass the check with check_pass before each TTL lapses to stay healthy.

    ConsulDiscovery

    pub struct ConsulDiscovery {
    client : ConsulClient
    }

    A consul-backed service registry / resolver over a ConsulClient. Each instance is a consul service named service, uniquely identified per agent by its address.

    ConsulDiscovery::deregister

    fn ConsulDiscovery::deregister(self : ConsulDiscovery, service : String) -> Unit raise

    Deregister every instance of service registered on this agent.

    ConsulDiscovery::deregister_instance

    fn ConsulDiscovery::deregister_instance(self : ConsulDiscovery, service : String, endpoint :
    Endpoint
    ) -> Unit raise

    Deregister one instance of service.

    ConsulDiscovery::keepalive

    fn ConsulDiscovery::keepalive(self : ConsulDiscovery, service : String, endpoint :
    Endpoint
    ) -> Unit raise

    Refresh an instance's lease by passing its TTL check.

    ConsulDiscovery::new

    A consul discovery over client.

    ConsulDiscovery::register

    fn ConsulDiscovery::register(self : ConsulDiscovery, service : String, endpoint :
    Endpoint
    , ttl? : Int) -> String raise

    Register endpoint for service with a ttl-second TTL check and immediately pass the check so the instance is healthy at once (a fresh TTL check starts critical). Returns the instance id; renew it with keepalive before the TTL lapses.

    ConsulDiscovery::resolve

    Resolve service to its healthy endpoints.

    ConsulDiscovery::resolver

    This consul discovery as a Resolve interface value, so the balancer and the load-balanced channel run against consul unchanged. A resolve error surfaces as an empty endpoint set, matching the other drivers.

    ConsulResponse

    pub struct ConsulResponse {
    status : Int
    body : Bytes
    }

    A consul agent's HTTP response: the status code and the raw body bytes.

    ConsulResponse::body

    fn ConsulResponse::body(self : ConsulResponse) -> Bytes

    The raw response body bytes.

    ConsulResponse::new

    fn ConsulResponse::new(status : Int, body : Bytes) -> ConsulResponse

    A consul response.

    ConsulResponse::status

    fn ConsulResponse::status(self : ConsulResponse) -> Int

    The HTTP status code.

    consul_check_id

    fn consul_check_id(service_id : String) -> String

    The check id consul assigns an inline service TTL check: service:<service-id>.

    consul_int_field

    fn consul_int_field(obj : Json, key : String) -> Int

    The integer value of a JSON number key, truncated toward zero, or 0.

    consul_parse_health

    fn consul_parse_health(body : Bytes) -> Array[
    Endpoint
    ] raise ConsulError

    Parse a consul health/service JSON body into endpoints — exposed so the native HTTP-socket path decodes a real agent's response exactly as the client does.

    consul_register_body

    fn consul_register_body(id : String, name : String, address : String, port : Int, ttl_secs : Int) -> Bytes

    The JSON body of a service/register request: the instance's id, name, address, and port, plus a TTL check that consul deregisters ttl*3 seconds after it stops passing. Exposed so the native HTTP-socket path builds the exact same body.

    consul_str_field

    fn consul_str_field(obj : Json, key : String) -> String

    The string value of key in a JSON object, or "".