A service is a special kind of resource that besides Resource properties, it could offer:

  • Its own REST API endpoints, using an express router, to expose details about service, this endpoints will be exposed under the observability paths.
  • A links property to define the endpoints that the service expose, this information will be exposed in the observability paths.
  • A metrics property to expose the metrics of the service, this registry will be merged with the global metrics registry.
interface Service {
    checks: Checks;
    close: () => Promise<void>;
    componentId: string;
    links?: Links;
    metrics?: Registry<"text/plain; version=0.0.4; charset=utf-8">;
    name: string;
    router?: Router;
    start: () => Promise<void>;
    status: "pass" | "fail" | "warn";
    stop: () => Promise<void>;
    on(event: "error", listener: (error: Multi | Error | Crash) => void): this;
    on(
        event: "status",
        listener: (status: "pass" | "fail" | "warn") => void,
    ): this;
}

Hierarchy (View Summary)

Implemented by

Properties

checks: Checks

Checks performed over this component to achieve the resulted status

close: () => Promise<void>

Resource close function

componentId: string

Component identifier

links?: Links

Service base path

metrics?: Registry<"text/plain; version=0.0.4; charset=utf-8">

Get the metrics registry

name: string

Component name

router?: Router

Express router

start: () => Promise<void>

Resource start function

status: "pass" | "fail" | "warn"

Resource status

stop: () => Promise<void>

Resource stop function

Methods

  • Add a listener for the error event, emitted when the component detects an error.

    Parameters

    • event: "error"

      error event

    • listener: (error: Multi | Error | Crash) => void

      Error event listener

    Returns this

  • Add a listener for the status event, emitted when the component status changes.

    Parameters

    • event: "status"

      status event

    • listener: (status: "pass" | "fail" | "warn") => void

      Status event listener

    Returns this