Options
All
  • Public
  • Public/Protected
  • All
Menu

Class CommandableGrpcService

Abstract service that receives commands via GRPC protocol to operations automatically generated for commands defined in ICommandable components. Each command is exposed as invoke method that receives command name and parameters.

Commandable services require only 3 lines of code to implement a robust external GRPC-based remote interface.

Configuration parameters

  • dependencies:
    • endpoint: override for HTTP 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

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

CommandableGrpcClient

see

GrpcService

Example

class MyCommandableGrpcService extends CommandableGrpcService {
   public constructor() {
      base();
      this._dependencyResolver.put(
          "controller",
          new Descriptor("mygroup","controller","*","*","1.0")
      );
   }
}

let service = new MyCommandableGrpcService();
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

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

register

  • register(): 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