Options
All
  • Public
  • Public/Protected
  • All
Menu

Class GrpcService

Abstract service that receives remove calls via GRPC protocol.

Configuration parameters

  • dependencies:
    • endpoint: override for GRPC Endpoint dependency
    • controller: override for Controller 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
  • credential - the HTTPS credentials:
    • ssl_key_file: the SSL private key in PEM
    • ssl_crt_file: the SSL certificate in PEM
    • ssl_ca_file: the certificate authorities (root cerfiticates) in PEM

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:grpc:*:1.0 (optional) GrpcEndpoint reference
see

GrpcClient

Example

class MyGrpcService extends GrpcService {
   private _controller: IMyController;
   ...
   public constructor() {
      base('... path to proto ...', '.. service name ...');
      this._dependencyResolver.put(
          "controller",
          new Descriptor("mygroup","controller","*","*","1.0")
      );
   }

   public setReferences(references: IReferences): void {
      base.setReferences(references);
      this._controller = this._dependencyResolver.getRequired<IMyController>("controller");
   }

   public register(): void {
       registerMethod("get_mydata", null, (call, callback) => {
           let correlationId = call.request.correlationId;
           let id = call.request.id;
           this._controller.getMyData(correlationId, id, callback);
       });
       ...
   }
}

let service = new MyGrpcService();
service.configure(ConfigParams.fromTuples(
    "connection.protocol", "http",
    "connection.host", "localhost",
    "connection.port", 8080
));
service.setReferences(References.fromTuples(
   new Descriptor("mygroup","controller","default","default","1.0"), controller
));

service.open("123", (err) => {
   console.log("The GRPC service is running on port 8080");
});

Hierarchy

Implements

Index

Constructors

constructor

  • new GrpcService(serviceOrPath: any, serviceName?: string, packageOptions?: any): GrpcService
  • Parameters

    • serviceOrPath: any
    • Optional serviceName: string
    • Optional packageOptions: any

    Returns GrpcService

Properties

Protected _counters

_counters: CompositeCounters = new CompositeCounters()

The performance counters.

Protected _dependencyResolver

_dependencyResolver: DependencyResolver = new DependencyResolver(GrpcService._defaultConfig)

The dependency resolver.

Protected _endpoint

_endpoint: GrpcEndpoint

The GRPC endpoint that exposes this service.

Protected _logger

_logger: CompositeLogger = new CompositeLogger()

The logger.

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

Abstract register

  • register(): void
  • Registers all service routes in HTTP endpoint.

    This method is called by the service and must be overriden in child classes.

    Returns void

Protected registerCommadableMethod

  • registerCommadableMethod(method: string, schema: Schema, action: function): void
  • Registers a commandable method in this objects GRPC server (service) by the given name.,

    Parameters

    • method: string

      the GRPC method name.

    • schema: Schema

      the schema to use for parameter validation.

    • action: function

      the action to perform at the given route.

        • (correlationId: string, data: any, callback: function): void
        • Parameters

          • correlationId: string
          • data: any
          • callback: function
              • (err: any, result: any): void
              • Parameters

                • err: any
                • result: any

                Returns void

          Returns void

    Returns void

Protected registerInterceptor

  • registerInterceptor(action: function): void
  • Registers a middleware for methods in GRPC endpoint.

    Parameters

    • action: function

      an action function that is called when middleware is invoked.

        • (call: any, callback: function, next: function): void
        • Parameters

          • call: any
          • callback: function
              • (err: any, result: any): void
              • Parameters

                • err: any
                • result: any

                Returns void

          • next: function
              • (): void
              • Returns void

          Returns void

    Returns void

Protected registerMethod

  • registerMethod(name: string, schema: Schema, action: function): void
  • Registers a method in GRPC service.

    Parameters

    • name: string

      a method name

    • schema: Schema

      a validation schema to validate received parameters.

    • action: function

      an action function that is called when operation is invoked.

        • (call: any, callback: function): void
        • Parameters

          • call: any
          • callback: function
              • (err: any, message: any): void
              • Parameters

                • err: any
                • message: any

                Returns void

          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

unsetReferences

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

    Returns void

Generated using TypeDoc