Options
All
  • Public
  • Public/Protected
  • All
Menu

Class CommandableGrpcClient

Abstract client that calls commandable GRPC service.

Commandable services are generated automatically for ICommandable objects. Each command is exposed as Invoke method that receives all parameters as args.

Configuration parameters

  • 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
  • options:
    • retries: number of retries (default: 3)
    • connect_timeout: connection timeout in milliseconds (default: 10 sec)
    • timeout: invocation timeout in milliseconds (default: 10 sec)

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

Example

class MyCommandableGrpcClient extends CommandableGrpcClient implements IMyClient {
   ...

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

       this.callCommand(
           "get_data",
           correlationId,
           { id: id },
           (err, result) => {
               callback(err, result);
           }
        );
    }
    ...
}

let client = new MyCommandableGrpcClient();
client.configure(ConfigParams.fromTuples(
    "connection.protocol", "http",
    "connection.host", "localhost",
    "connection.port", 8080
));

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

Hierarchy

Implements

  • any
  • any
  • any

Index

Constructors

constructor

Properties

Protected _client

_client: any

The GRPC client.

Protected _connectTimeout

_connectTimeout: number = 10000

The connection timeout in milliseconds.

Protected _connectionResolver

_connectionResolver: HttpConnectionResolver = new HttpConnectionResolver()

The connection resolver.

Protected _counters

_counters: CompositeCounters = new CompositeCounters()

The performance counters.

Protected _logger

_logger: CompositeLogger = new CompositeLogger()

The logger.

Protected _name

_name: string

The service name

Protected _options

_options: ConfigParams = new ConfigParams()

The configuration options.

Protected _timeout

_timeout: number = 10000

The invocation timeout in milliseconds.

Protected _uri

_uri: string

The remote service uri which is calculated on open.

Methods

Protected call

  • call(method: string, correlationId?: string, request?: any, callback?: function): void
  • Calls a remote method via GRPC protocol.

    Parameters

    • method: string

      a method name to called

    • Optional correlationId: string

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

    • Default value request: any = {}

      (optional) request object.

    • Optional callback: function

      (optional) callback function that receives result object or error.

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

          • err: any
          • result: any

          Returns void

    Returns void

callCommand

  • callCommand(name: string, correlationId: string, params: any, callback: function): void
  • Calls a remote method via GRPC commadable protocol. The call is made via Invoke method and all parameters are sent in args object. The complete route to remote method is defined as serviceName + "." + name.

    Parameters

    • name: string

      a name of the command to call.

    • correlationId: string

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

    • params: any

      command parameters.

    • callback: function

      callback function that receives result or error.

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

          • err: any
          • result: any

          Returns void

    Returns void

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