Options
All
  • Public
  • Public/Protected
  • All
Menu

Class SenecaService

Abstract service that receives remove calls via Seneca protocol.

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

SenecaClient

Example

class MySenecaService extends SenecaService {
   private _controller: IMyController;
   ...
   public constructor() {
      base();
      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 {
       registerAction("mydata", "get_data", null, (params, callback) => {
           let correlationId = params.correlation_id;
           let id = params.id;
           this._controller.getMyData(correlationId, id, callback);
       });
       ...
   }
}

let service = new MySenecaService();
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 Seneca service is running on port 8080");
});

Hierarchy

Implements

  • IOpenable
  • IConfigurable
  • IReferenceable

Index

Properties

Protected _connectionResolver

_connectionResolver: ConnectionResolver = new ConnectionResolver()

Protected _counters

_counters: CompositeCounters = new CompositeCounters()

Protected _dependencyResolver

_dependencyResolver: DependencyResolver = new DependencyResolver(SenecaService._defaultConfig)

Protected _logger

_logger: CompositeLogger = new CompositeLogger()

Protected _opened

_opened: boolean = false

Protected _seneca

_seneca: any

Protected transport

transport: any

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

          • Optional 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): 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
  • 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.

    • callback: function

      callback function that receives error or null no errors occured.

        • (err?: any): void
        • Parameters

          • Optional err: any

          Returns void

    Returns void

Protected Abstract register

  • register(): void
  • Registers all service actions.

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

    Returns void

Protected registerAction

  • registerAction(role: string, cmd: string, schema: any, action: function): void
  • Registers an action in Seneca endpoint.

    Parameters

    • role: string

      a service role (name)

    • cmd: string

      a command name

    • schema: any

      a validation schema to validate received parameters.

    • action: function

      an action function that is called when action is invoked.

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

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

                • err: any
                • result: any

                Returns void

          Returns void

    Returns void

Protected resolveConnection

  • resolveConnection(correlationId: string, callback: function): void
  • Resolves and validates connection for 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
  • Sets references to dependent components.

    Parameters

    • references: IReferences

      references to locate the component dependencies.

    Returns void

Generated using TypeDoc