Examples

Example 1

import { createApplication } from '@setu-ts/kernel';
import { RuntimePlugin } from '@setu-ts/runtime';
import { ServiceDiscoveryPlugin } from '@setu-ts/service-discovery-plugin';
import { CAPABILITIES, type IServiceDiscovery } from '@setu-ts/common';

const app = createApplication({
  plugins: [
    RuntimePlugin(),
    ServiceDiscoveryPlugin({
      provider: 'consul',
      address: 'http://127.0.0.1:8500',
    }),
  ],
});

await app.start({ port: 3000 });

const discovery = app.services.get<IServiceDiscovery>(
  CAPABILITIES.SERVICE_DISCOVERY,
);
const url = await discovery.resolveUrl('billing', '/invoices');

Classes

c
ConsulProvider(
options: ConsulProviderOptions,
http: IDiscoveryHttp,
runtime: IRuntimeServices
)

Reads and registers against a Consul agent.

c
DiscoveryUnavailableError(
message: string,
options?: ErrorOptions
)

Discovery could not answer.

c
DnsProvider(
resolver: IDnsResolver,
runtime: IRuntimeServices,
options: DnsProviderOptions
)

Resolves services through DNS.

c
KubernetesProvider(
options: KubernetesProviderOptions,
http: IDiscoveryHttp,
runtime: IRuntimeServices
)

Reads EndpointSlices for a service.

c
SelfRegistrationNotSupportedError(provider: string)

selfRegistration was configured against a provider that cannot register.

c
StaticProvider(
services: Readonly<Record<string, readonly StaticServiceDefinition[]>>,
runtime: IRuntimeServices
)

Serves a configured instance list.

Functions

Interfaces

I
ADnsDiscoveryOptions

The 'dns' arm in address mode — A/AAAA records carry no port.

I
ConsulDiscoveryOptions

The 'consul' arm.

I
ConsulProviderOptions

Constructor options.

I
CustomDiscoveryOptions

The 'custom' arm — the application's own backend.

I
DiscoveryHttpResponse

A buffered HTTP response, as IDiscoveryHttp.request returns it.

I
DiscoveryHttpStream

A streaming HTTP response, as IDiscoveryHttp.stream returns it.

I
DiscoveryProvider

A discovery backend.

I
EjectionOptions

Outlier-ejection tuning.

I
IDiscoveryHttp

The HTTP surface the Consul and Kubernetes providers need.

I
KubernetesDiscoveryOptions

The 'kubernetes' arm — EndpointSlices read from the API server.

I
KubernetesProviderOptions

Constructor options.

I
SelfRegistration

What this application advertises about itself.

I
SelfRegistrationCheck

The health check the backend runs against this instance after registration.

I
SrvDnsDiscoveryOptions

The 'dns' arm in SRV mode — records carry their own ports.

  • mode: "srv"

    Query SRV records and honor RFC 2782 priority tiers.

I
StaticDiscoveryOptions

The 'static' arm — a literal instance list, with no backend at all.

I
StaticServiceDefinition

One entry of a 'static' service list.

Type Aliases

Usage

import * as Service_discovery_for_Setu_TS___turns_a_logical_service_name_into_a_reachable_address__balances_across_the_instances_behind_it__and_takes_them_out_of_rotation_when_callers_report_failures___Registers_an__IServiceDiscovery__under__CAPABILITIES_SERVICE_DISCOVERY___backed_by_a_pluggable_provider__a_literal___static___list____consul______kubernetes___EndpointSlices____dns____SRV_and_address_records___or_the_application_s_own___custom___provider__Zero_npm_dependencies___the_HTTP_providers_run_on_web_standard__fetch__and_the_DNS_provider_on_the_optional__IRuntimeServices_dns___ from "service-discovery-plugin/src/index.ts";