Options
All
  • Public
  • Public/Protected
  • All
Menu

Class HeartbeatRestService

Service returns heartbeat via HTTP/REST protocol.

The service responds on /heartbeat route (can be changed) with a string with the current time in UTC.

This service route can be used to health checks by loadbalancers and container orchestrators.

Configuration parameters

  • base_route: base route for remote URI (default: "")
  • route: route to heartbeat operation (default: "heartbeat")
  • dependencies:
    • endpoint: override for HTTP Endpoint dependency
  • connection(s):
    • discovery_key: (optional) a key to retrieve the connection from IDiscovery
    • protocol: connection protocol: http or https
    • host: host name or IP address
    • port: port number
    • uri: resource URI or connection string with all parameters in it

References

  • *:logger:*:*:1.0 (optional) ILogger components to pass log messages
  • *:counters:*:*:1.0 (optional) ICounters components to pass collected measurements
  • *:discovery:*:*:1.0 (optional) IDiscovery services to resolve connection
  • *:endpoint:http:*:1.0 (optional) HttpEndpoint reference
see

RestService

see

RestClient

Example

let service = new HeartbeatService();
service.configure(ConfigParams.fromTuples(
    "route", "ping",
    "connection.protocol", "http",
    "connection.host", "localhost",
    "connection.port", 8080
));

service.open("123", (err) => {
   console.log("The Heartbeat service is accessible at http://+:8080/ping");
});

Hierarchy

Implements

Index

Constructors

constructor

  • Creates a new instance of this service.

    Returns HeartbeatRestService

Properties

Protected _baseRoute

_baseRoute: string

The base route.

Protected _config

_config: ConfigParams

Protected _counters

_counters: CompositeCounters = new CompositeCounters()

The performance counters.

Protected _dependencyResolver

_dependencyResolver: DependencyResolver = new DependencyResolver(RestService._defaultConfig)

The dependency resolver.

Protected _endpoint

_endpoint: HttpEndpoint

The HTTP endpoint that exposes this service.

Protected _logger

_logger: CompositeLogger = new CompositeLogger()

The logger.

Protected _swaggerEnable

_swaggerEnable: boolean = false

Protected _swaggerRoute

_swaggerRoute: string = "swagger"

Protected _swaggerService

_swaggerService: ISwaggerService

Methods

close

  • close(correlationId: string, callback?: function): void
  • Closes component and frees used resources.

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • Optional callback: function

      callback function that receives error or null no errors occured.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

configure

  • configure(config: ConfigParams): void
  • Configures component by passing configuration parameters.

    Parameters

    • config: ConfigParams

      configuration parameters to be set.

    Returns void

getCorrelationId

  • getCorrelationId(req: any): string
  • Returns correlationId from request

    Parameters

    • req: any

      http request

    Returns string

    Returns correlationId from request

Protected instrument

  • instrument(correlationId: string, name: string): CounterTiming
  • Adds instrumentation to log calls and measure call time. It returns a CounterTiming object that is used to end the time measurement.

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • name: string

      a method name.

    Returns CounterTiming

    CounterTiming object to end the time measurement.

Protected instrumentError

  • instrumentError(correlationId: string, name: string, err: any, result?: any, callback?: function): void
  • Adds instrumentation to error handling.

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • name: string

      a method name.

    • err: any

      an occured error

    • Default value result: any = null

      (optional) an execution result

    • Default value callback: function = null

      (optional) an execution callback

        • (err: any, result: any): void
        • Parameters

          • err: any
          • result: any

          Returns void

    Returns void

isOpen

  • isOpen(): boolean
  • Checks if the component is opened.

    Returns boolean

    true if the component has been opened and false otherwise.

open

  • open(correlationId: string, callback?: function): void
  • Opens the component.

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • Optional callback: function

      callback function that receives error or null no errors occured.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

register

  • register(): void

Protected registerInterceptor

  • registerInterceptor(route: string, action: function): void
  • Registers a middleware for a given route in HTTP endpoint.

    Parameters

    • route: string

      a command route. Base route will be added to this route

    • action: function

      an action function that is called when middleware is invoked.

        • (req: any, res: any, next: function): void
        • Parameters

          • req: any
          • res: any
          • next: function
              • (): void
              • Returns void

          Returns void

    Returns void

Protected registerOpenApiSpec

  • registerOpenApiSpec(content: string): void

Protected registerOpenApiSpecFromFile

  • registerOpenApiSpecFromFile(path: string): void

Protected registerRoute

  • registerRoute(method: string, route: string, schema: Schema, action: function): void
  • Registers a route in HTTP endpoint.

    Parameters

    • method: string

      HTTP method: "get", "head", "post", "put", "delete"

    • route: string

      a command route. Base route will be added to this route

    • schema: Schema

      a validation schema to validate received parameters.

    • action: function

      an action function that is called when operation is invoked.

        • (req: any, res: any): void
        • Parameters

          • req: any
          • res: any

          Returns void

    Returns void

Protected registerRouteWithAuth

  • registerRouteWithAuth(method: string, route: string, schema: Schema, authorize: function, action: function): void
  • Registers a route with authorization in HTTP endpoint.

    Parameters

    • method: string

      HTTP method: "get", "head", "post", "put", "delete"

    • route: string

      a command route. Base route will be added to this route

    • schema: Schema

      a validation schema to validate received parameters.

    • authorize: function

      an authorization interceptor

        • (req: any, res: any, next: function): void
        • Parameters

          • req: any
          • res: any
          • next: function
              • (): void
              • Returns void

          Returns void

    • action: function

      an action function that is called when operation is invoked.

        • (req: any, res: any): void
        • Parameters

          • req: any
          • res: any

          Returns void

    Returns void

Protected sendCreatedResult

  • sendCreatedResult(req: any, res: any): function
  • Creates a callback function that sends newly created object as JSON. That callack function call be called directly or passed as a parameter to business logic components.

    If object is not null it returns 201 status code. For null results it returns 204 status code. If error occur it sends ErrorDescription with approproate status code.

    Parameters

    • req: any

      a HTTP request object.

    • res: any

      a HTTP response object.

    Returns function

      • (err: any, result: any): void
      • Parameters

        • err: any
        • result: any

        Returns void

Protected sendDeletedResult

  • sendDeletedResult(req: any, res: any): function
  • Creates a callback function that sends deleted object as JSON. That callack function call be called directly or passed as a parameter to business logic components.

    If object is not null it returns 200 status code. For null results it returns 204 status code. If error occur it sends ErrorDescription with approproate status code.

    Parameters

    • req: any

      a HTTP request object.

    • res: any

      a HTTP response object.

    Returns function

      • (err: any, result: any): void
      • Parameters

        • err: any
        • result: any

        Returns void

Protected sendError

  • sendError(req: any, res: any, error: any): void
  • Sends error serialized as ErrorDescription object and appropriate HTTP status code. If status code is not defined, it uses 500 status code.

    Parameters

    • req: any

      a HTTP request object.

    • res: any

      a HTTP response object.

    • error: any

      an error object to be sent.

    Returns void

Protected sendResult

  • sendResult(req: any, res: any): function
  • Creates a callback function that sends result as JSON object. That callack function call be called directly or passed as a parameter to business logic components.

    If object is not null it returns 200 status code. For null results it returns 204 status code. If error occur it sends ErrorDescription with approproate status code.

    Parameters

    • req: any

      a HTTP request object.

    • res: any

      a HTTP response object.

    Returns function

      • (err: any, result: any): void
      • Parameters

        • err: any
        • result: any

        Returns void

setReferences

  • setReferences(references: IReferences): void
  • Sets references to dependent components.

    Parameters

    • references: IReferences

      references to locate the component dependencies.

    Returns void

unsetReferences

  • unsetReferences(): void
  • Unsets (clears) previously set references to dependent components.

    Returns void

Generated using TypeDoc