Setu-TS
    Preparing search index...

    Interface IServiceDiscovery

    Resolves logical service names to reachable instances, balances across them, and learns from reported call outcomes.

    Registered under CAPABILITIES.SERVICE_DISCOVERY.

    const discovery = ctx.services.get<IServiceDiscovery>(
    CAPABILITIES.SERVICE_DISCOVERY,
    );

    const instance = await discovery.pick('billing');
    if (instance === null) throw new Error('no billing instance');

    try {
    const url = await discovery.resolveUrl('billing', '/invoices');
    const response = await fetch(url!);
    discovery.report(instance, response.ok ? 'success' : 'failure');
    } catch (error) {
    discovery.report(instance, 'failure');
    throw error;
    }

    0.2.0

    interface IServiceDiscovery {
        pick(
            serviceName: string,
            options?: PickOptions,
        ): Promise<ServiceInstance | null>;
        report(instance: ServiceInstance, outcome: ServiceOutcome): void;
        resolve(serviceName: string): Promise<readonly ServiceInstance[]>;
        resolveUrl(
            serviceName: string,
            path?: string,
            options?: PickOptions,
        ): Promise<string | null>;
        watch(
            serviceName: string,
            listener: (instances: readonly ServiceInstance[]) => void,
        ): Promise<Unsubscribe>;
    }
    Index
    • Lists every instance discovery knows for a service.

      Reports what the backend says, so ejected instances are included — ejection is a IServiceDiscovery.pick concern, not a knowledge one. An unknown service name resolves to an empty list rather than throwing.

      Parameters

      • serviceName: string

        Logical service name

      Returns Promise<readonly ServiceInstance[]>

      Every known instance, possibly empty

      If the backend fails and nothing is cached

    • Formats IServiceDiscovery.pick's choice as an absolute URL.

      Parameters

      • serviceName: string

        Logical service name

      • Optionalpath: string

        Path appended to the instance's origin

      • Optionaloptions: PickOptions

        Per-call strategy override

      Returns Promise<string | null>

      The URL, or null when the service has no instance

    • Subscribes to instance-list changes for a service.

      Push-based where the backend supports it (Consul blocking queries, Kubernetes watch streams) and interval-polled where it does not (DNS, static). The listener receives the full current list, never a delta.

      Parameters

      • serviceName: string

        Logical service name

      • listener: (instances: readonly ServiceInstance[]) => void

        Called with the full instance list on every change

      Returns Promise<Unsubscribe>

      Unsubscribe function that also stops the underlying watch