PrimeBrickPrimeBrick
  • Docs
  • Contact
  • MIT License
  • Documentation
  • MCP Server
  • API Catalog
  • Services
  • Libraries
PrimeBrickPrimeBrick

© 2026 PrimeBrick. MIT License. v3.8.0

github
DAL Library
SDK Library
    OverviewGetting StartedAuthenticationExt-JSONRedis cache layerConfig tables & ConfigLoaderNATS™ ClientService RegistrationHTTP ServerSSE StandardPresenceAPI Reference
powered by Zudoku
SDK Library

Service Registration

ServiceRegistrar registers a microservice via NATS™ lifecycle events and maintains a heartbeat. The BE subscribes to these events and persists the state to the service_registry table. The microservice never touches the database directly.

Lifecycle events

Three NATS™ subjects carry lifecycle events:

SubjectWhenPayload
service.registerOn startupServiceRegisterPayload — code, base_url, endpoints, health, metadata
service.heartbeatEvery 30s (default)ServiceHeartbeatPayload — code, base_url, health, metadata
service.unregisterOn graceful shutdownServiceUnregisterPayload — code, base_url

These subjects are defined in the SERVICE_SUBJECTS constant.

Usage

Code
import { NatsClient, ServiceRegistrar } from "@primebrick/sdk"; const registrar = new ServiceRegistrar(NatsClient, { serviceCode: "emailsender", baseUrl: "http://emailsender:3001", endpoints: { "POST /send": {} }, name: "Email Sender", description: "Sends emails via configured providers", author: "Primebrick", github_repo_url: "https://github.com/michaelsogos/primebrick-us-v3", service_version: "1.0.0", is_behind_scaler: true, }, async () => ({ http_healthy: true, checks: { nats: { ok: NatsClient.isConnected() }, db: { ok: await dbPing() }, }, })); // Register on startup await registrar.register(); // Start heartbeat loop (30s interval) registrar.startHeartbeat(); // On graceful shutdown await registrar.unregister(); registrar.stopHeartbeat();

Health checks

The healthCheckFn (third constructor argument) is called on each heartbeat to include the current health status. It returns http_healthy (boolean) and checks (a record of named checks with ok and optional error).

If no healthCheckFn is provided, the registrar defaults to http_healthy: true with empty checks.

Configuration options

ServiceRegistrarConfig supports:

FieldRequiredDescription
serviceCodeyesUnique service identifier
baseUrlyesService URL (used by BE for direct mode routing)
endpointsyesMap of endpoint signatures
heartbeatIntervalMsnoHeartbeat interval (default: 30000)
namenoDisplay name
descriptionnoService description
authornoAuthor name
github_repo_urlnoRepository URL
service_versionnoSemver string
is_behind_scalernoWhether the service is behind a scaler (default: false)
icon / icon_typenoIcon for UI display

ServiceRegistryPort

The BE implements ServiceRegistryPort to persist lifecycle events. The port interface supports both scaler mode (one row per code) and direct mode (multiple rows per code, distinguished by base_url):

MethodModeDescription
findByCode(code)bothFind one row by code
findByCodeAndBaseUrl(code, baseUrl)directFind by code + URL
findAllByCode(code)directAll rows for a code
findAll()bothAll rows
insert(row)bothInsert new row
updateByCode(code, row)scalerUpdate by code
updateByCodeAndBaseUrl(code, baseUrl, row)directUpdate by code + URL
deleteByCodeAndBaseUrl(code, baseUrl)directDelete by code + URL

Next steps

  • NATS Client — the transport used by ServiceRegistrar
  • Authentication — auth for NATS™ subscribers
  • API Reference — ServiceRegistrar and payload types
Last modified on July 26, 2026
NATS™ ClientHTTP Server
On this page
  • Lifecycle events
  • Usage
  • Health checks
  • Configuration options
  • ServiceRegistryPort
  • Next steps
TypeScript