Options
All
  • Public
  • Public/Protected
  • All
Menu

Class CommandableSenecaClient

Abstract client that calls commandable Seneca service.

Commandable services are generated automatically for ICommandable objects. Each command is exposed as Seneca action.

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 MyCommandableSenecaClient extends CommandableSenecaClient 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 MyCommandableSenecaClient();
client.configure(ConfigParams.fromTuples(
    "connection.protocol", "http",
    "connection.host", "localhost",
    "connection.port", 8080
));

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

Hierarchy

Implements

  • IOpenable
  • IConfigurable
  • IReferenceable

Index

Constructors

constructor

Properties

Protected _connectionResolver

_connectionResolver: ConnectionResolver = new ConnectionResolver()

Protected _counters

_counters: CompositeCounters = new CompositeCounters()

Protected _dependencyResolver

_dependencyResolver: DependencyResolver = new DependencyResolver(SenecaClient._defaultConfig)

Protected _logger

_logger: CompositeLogger = new CompositeLogger()

Protected _opened

_opened: boolean = false

Protected _schemas

_schemas: object

Type declaration

  • [id: string]: Schema

Protected _seneca

_seneca: any

Methods

Protected call

  • call(role: string, cmd: string, correlationId: string, params?: any, callback?: function): void
  • Calls a remote method via HTTP/REST protocol.

    Parameters

    • role: string

      a service role (service name)

    • cmd: string

      a command name

    • correlationId: string

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

    • Default value params: any = {}

      (optional) command parameters.

    • 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(cmd: string, correlationId: string, params: any, callback: function): void
  • Calls a remote method via Seneca commadable protocol.

    Parameters

    • cmd: 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

          • Optional err: any

          Returns void

    Returns void

configure

  • configure(config: ConfigParams): void

Protected instrument

  • instrument(correlationId: string, name: string): Timing
  • Adds instrumentation to log calls and measure call time. It returns a Timing 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 Timing

    Timing object to end the time measurement.

isOpen

  • isOpen(): boolean

open

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

    Parameters

    • correlationId: string

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

    • callback: function

      callback function that receives error or null no errors occured.

        • (err?: any): void
        • Parameters

          • Optional err: any

          Returns void

    Returns void

Protected resolveConnection

  • resolveConnection(correlationId: string, callback: function): void
  • Resolves and validates connection to Seneca service.

    Parameters

    • correlationId: string

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

    • callback: function

      callback function that receives connection parameters or error.

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

          • err: any
          • result: ConnectionParams

          Returns void

    Returns void

setReferences

  • setReferences(references: IReferences): void

Generated using TypeDoc