Options
All
  • Public
  • Public/Protected
  • All
Menu

Class DirectClient<T>

Abstract client that calls controller directly in the same memory space.

It is used when multiple microservices are deployed in a single container (monolyth) and communication between them can be done by direct calls rather then through the network.

Configuration parameters

  • dependencies:
    • controller: override controller descriptor

References

  • *:logger:*:*:1.0 (optional) ILogger components to pass log messages
  • *:counters:*:*:1.0 (optional) ICounters components to pass collected measurements
  • *:controller:*:*:1.0 controller to call business methods

Example

class MyDirectClient extends DirectClient<IMyController> implements IMyClient {

    public constructor() {
      super();
      this._dependencyResolver.put('controller', new Descriptor(
          "mygroup", "controller", "*", "*", "*"));
    }
    ...

    public getData(correlationId: string, id: string,
      callback: (err: any, result: MyData) => void): void {

      let timing = this.instrument(correlationId, 'myclient.get_data');
      this._controller.getData(correlationId, id, (err, result) => {
         timing.endTiming();
         this.instrumentError(correlationId, 'myclient.get_data', err, result, callback);
      });
    }
    ...
}

let client = new MyDirectClient();
client.setReferences(References.fromTuples(
    new Descriptor("mygroup","controller","default","default","1.0"), controller
));

client.getData("123", "1", (err, result) => {
  ...
});

Type parameters

  • T

Hierarchy

  • DirectClient

Implements

  • any
  • any
  • any

Index

Constructors

constructor

  • Creates a new instance of the client.

    Returns DirectClient

Properties

Protected _controller

_controller: T

The controller reference.

Protected _counters

_counters: CompositeCounters = new CompositeCounters()

The performance counters

Protected _dependencyResolver

_dependencyResolver: DependencyResolver = new DependencyResolver()

The dependency resolver to get controller reference.

Protected _logger

_logger: CompositeLogger = new CompositeLogger()

The logger.

Protected _opened

_opened: boolean = true

The open flag.

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

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

setReferences

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

    Parameters

    • references: IReferences

      references to locate the component dependencies.

    Returns void

Generated using TypeDoc