services

package
v1.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 28, 2021 License: MIT Imports: 16 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommandableGrpcService

type CommandableGrpcService struct {
	GrpcService
	// contains filtered or unexported fields
}

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:

    type MyCommandableGrpcService struct {
        *CommandableGrpcService
    }

	func NewCommandableGrpcService() *CommandableGrpcService {
        c := DummyCommandableGrpcService{}
        c.CommandableGrpcService = grpcservices.NewCommandableGrpcService("myservice")
        c.DependencyResolver.Put("controller", cref.NewDescriptor("mygroup", "controller", "default", "*", "*"))
        return &c
    }

    service := NewMyCommandableGrpcService();
    service.Configure(cconf.NewConfigParamsFromTuples(
        "connection.protocol", "http",
        "connection.host", "localhost",
        "connection.port", "8080",
    ));
    service.SetReferences(cref.NewReferencesFromTuples(
       cref.NewDescriptor("mygroup","controller","default","default","1.0"), controller
    ));

    opnErr:= service.Open("123")
    if opnErr == nil {
        console.log("The GRPC service is running on port 8080");
    }

func InheritCommandableGrpcService added in v1.1.0

func InheritCommandableGrpcService(overrides IGrpcServiceOverrides, name string) *CommandableGrpcService

NewCommandableGrpcService method are creates a new instance of the service.

  • name a service name.

func (*CommandableGrpcService) Register

func (c *CommandableGrpcService) Register()

Register method are registers all service command in gRPC endpoint.

type GrpcEndpoint

type GrpcEndpoint struct {
	// contains filtered or unexported fields
}

GrpcEndpoint used for creating GRPC endpoints. An endpoint is a URL, at which a given service can be accessed by a client.

Configuration parameters:

Parameters to pass to the configure method for component configuration:

- connection(s) - the connection resolver"s connections:

  • "connection.discovery_key" - the key to use for connection resolving in a discovery service;
  • "connection.protocol" - the connection"s protocol;
  • "connection.host" - the target host;
  • "connection.port" - the target port;
  • "connection.uri" - the target URI.

- credential - the HTTPS credentials:

  • "credential.ssl_key_file" - the SSL private key in PEM
  • "credential.ssl_crt_file" - the SSL certificate in PEM
  • "credential.ssl_ca_file" - the certificate authorities (root cerfiticates) in PEM

References:

A logger, counters, and a connection resolver can be referenced by passing the following references to the object"s setReferences method:

- logger: "*:logger:*:*:1.0"; - counters: "*:counters:*:*:1.0"; - discovery: "*:discovery:*:*:1.0" (for the connection resolver).

Examples:

func (c* Endpoint) MyMethod(config ConfigParams, references IReferences) {
    endpoint := NewGrpcEndpoint();
    if c.config != nil {
        endpoint.Configure(c._config);
    }
    if c.references != nil {
        endpoint.SetReferences(c.references);
    }
    ...

    err := c.endpoint.Open(correlationId)
    if err != nil {
        // error ocured
        return err
    }
    c.Opened = true
    return nil
    ...
}

func NewGrpcEndpoint

func NewGrpcEndpoint() *GrpcEndpoint

NewGrpcEndpoint method are creates new instance of GrpcEndpoint

func (*GrpcEndpoint) AddInterceptors

func (c *GrpcEndpoint) AddInterceptors(interceptors ...grpc.ServerOption)

AddInterceptors method are registers a middleware for methods in GRPC endpoint. See https://github.com/grpc/grpc-go/tree/master/examples/features/interceptor Parameters:

  • interceptors ...grpc.ServerOption

interceptor functions (Stream or Unary use grpc.UnaryInterceptor() or grpc.StreamInterceptor() for inflate in grpc.ServerOption)

func (*GrpcEndpoint) Close

func (c *GrpcEndpoint) Close(correlationId string) (err error)

Close methods are closes c endpoint and the GRPC server (service) that was opened earlier. Parameters:

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

Returns: an error if one is raised.

func (*GrpcEndpoint) Configure

func (c *GrpcEndpoint) Configure(config *cconf.ConfigParams)

Configure method are configures c HttpEndpoint using the given configuration parameters. Configuration parameters:

  • connection(s) - the connection resolver"s connections;
  • "connection.discovery_key" - the key to use for connection resolving in a discovery service;
  • "connection.protocol" - the connection"s protocol;
  • "connection.host" - the target host;
  • "connection.port" - the target port;
  • "connection.uri" - the target URI.
  • "credential.ssl_key_file" - SSL private key in PEM
  • "credential.ssl_crt_file" - SSL certificate in PEM
  • "credential.ssl_ca_file" - Certificate authority (root certificate) in PEM

Parameters:

  • config configuration parameters, containing a "connection(s)" section.

See ConfigParams (in the PipServices "Commons" package)

func (*GrpcEndpoint) GetServer

func (c *GrpcEndpoint) GetServer() *grpc.Server

GetServer return working gRPC server for register services Returns *grpc.Server

func (*GrpcEndpoint) IsOpen

func (c *GrpcEndpoint) IsOpen() bool

IsOpen method are return whether or not c endpoint is open with an actively listening GRPC server.

func (*GrpcEndpoint) Open

func (c *GrpcEndpoint) Open(correlationId string) (err error)

Open method are opens a connection using the parameters resolved by the referenced connection resolver and creates a GRPC server (service) using the set options and parameters. Parameters:

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

Retunrns: an error if one is raised.

func (*GrpcEndpoint) Register

func (c *GrpcEndpoint) Register(registration IRegisterable)

Register method are registers a registerable object for dynamic endpoint discovery.

  • registration the registration to add.

See IRegisterable

func (*GrpcEndpoint) RegisterCommadableMethod

func (c *GrpcEndpoint) RegisterCommadableMethod(method string, schema *cvalid.Schema,
	action func(correlationId string, args *crun.Parameters) (result interface{}, err error))

RegisterCommadableMethod method are registers a commandable method in c objects GRPC server (service) by the given name.,

  • method the GRPC method name.
  • schema the schema to use for parameter validation.
  • action the action to perform at the given route.

func (*GrpcEndpoint) RegisterService

func (c *GrpcEndpoint) RegisterService(sd *grpc.ServiceDesc, implementation interface{})

RegisterService method are registers a service with related implementation

  • implementation the service implementation method Invoke.

func (*GrpcEndpoint) SetReferences

func (c *GrpcEndpoint) SetReferences(references cref.IReferences)

SetReferences method are sets references to c endpoint"s logger, counters, and connection resolver. References:

  • logger: "*:logger:*:*:1.0"
  • counters: "*:counters:*:*:1.0"
  • discovery: "*:discovery:*:*:1.0" (for the connection resolver)

Parameters:

  • references an IReferences object, containing references to a logger, counters, and a connection resolver.

See IReferences (in the PipServices "Commons" package)

func (*GrpcEndpoint) Unregister

func (c *GrpcEndpoint) Unregister(registration IRegisterable)

Unregister mwthod are unregisters a registerable object, so that it is no longer used in dynamic endpoint discovery.

  • registration the registration to remove.

See IRegisterable

type GrpcService

type GrpcService struct {
	Overrides IGrpcServiceOverrides

	//  The GRPC endpoint that exposes c service.
	Endpoint *GrpcEndpoint
	//  The dependency resolver.
	DependencyResolver *cref.DependencyResolver
	//  The logger.
	Logger *clog.CompositeLogger
	//  The performance counters.
	Counters *ccount.CompositeCounters
	// contains filtered or unexported fields
}

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 connect.idiscovery.html 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:

type MyGrpcService struct{
   *GrpcService
   controller IMyController;
}
...

   func NewMyGrpcService() *MyGrpcService {
       c := NewMyGrpcService{}
       c.GrpcService = grpcservices.NewGrpcService("Mydata.Mydatas")
       c.GrpcService.IRegisterable = &c
       c.numberOfCalls = 0
       c.DependencyResolver.Put("controller", cref.NewDescriptor("mygroup", "controller", "*", "*", "*"))
       return &c
   }

   func (c*MyGrpcService) SetReferences(references: IReferences) {
        c.GrpcService.SetReferences(references);
        resolv, err := c.DependencyResolver.GetOneRequired("controller")
        if err == nil && resolv != nil {
            c.controller = resolv.(grpctest.IMyController)
            return
        }
        panic("Can't resolve 'controller' reference")
   }

   func (c*MyGrpcService) Register() {
       protos.RegisterMyDataServer(c.Endpoint.GetServer(), c)
       ...
   }

service := NewMyGrpcService();
service.Configure(cconf.NewConfigParamsFromTuples(
    "connection.protocol", "http",
    "connection.host", "localhost",
    "connection.port", 8080,
));
service.SetReferences(cref.NewReferencesFromTuples(
   cref.NewDescriptor("mygroup","controller","default","default","1.0"), controller
));

err := service.Open("123")
if  err == nil {
   fmt.Println("The GRPC service is running on port 8080");
}

func InheritGrpcService added in v1.1.0

func InheritGrpcService(overrides IGrpcServiceOverrides, serviceName string) *GrpcService

InheritGrpcService methods are creates new instance NewGrpcService Parameters:

  • overrides a reference to child class that overrides virtual methods
  • serviceName string

service name from XYZ.pb.go, set "" for use default gRPC commandable protobuf Return *GrpcService

func (*GrpcService) Close

func (c *GrpcService) Close(correlationId string) (err error)

Close method are closes component and frees used resources. Parameters:

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

Returns: error or nil no errors occured.

func (*GrpcService) Configure

func (c *GrpcService) Configure(config *cconf.ConfigParams)

Configure method are configures component by passing configuration parameters.

  • config configuration parameters to be set.

func (*GrpcService) Instrument

func (c *GrpcService) Instrument(correlationId string, name string) *ccount.CounterTiming

Instrument method are adds instrumentation to log calls and measure call time. It returns a Timing object that is used to end the time measurement. Parameters:

  • correlationId (optional) transaction id to trace execution through call chain.
  • name a method name.

Return Timing object to end the time measurement.

func (*GrpcService) InstrumentError

func (c *GrpcService) InstrumentError(correlationId string, name string, errIn error,
	resIn interface{}) (result interface{}, err error)

InstrumentError method are adds instrumentation to error handling. Parameters:

  • correlationId (optional) transaction id to trace execution through call chain.
  • name a method name.
  • errIn an occured error
  • resIn (optional) an execution result

Returns: result interface{}, err error input result and error

func (*GrpcService) IsOpen

func (c *GrpcService) IsOpen() bool

IsOpen method are checks if the component is opened. Return true if the component has been opened and false otherwise.

func (*GrpcService) Open

func (c *GrpcService) Open(correlationId string) (err error)

Open method are opens the component. Parameters:

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

Returns: error or nil no errors occured.

func (*GrpcService) Register added in v1.1.0

func (c *GrpcService) Register()

Register method are registers all service routes in HTTP endpoint.

func (*GrpcService) RegisterCommadableMethod

func (c *GrpcService) RegisterCommadableMethod(method string, schema *cvalid.Schema,
	action func(correlationId string, data *crun.Parameters) (result interface{}, err error))

RegisterCommadableMethod method are registers a commandable method in c objects GRPC server (service) by the given name., Parameters:

  • method the GRPC method name.
  • schema the schema to use for parameter validation.
  • action the action to perform at the given route.

func (*GrpcService) SetReferences

func (c *GrpcService) SetReferences(references cref.IReferences)

SetReferences method are sets references to dependent components. Parameters:

  • references references to locate the component dependencies.

func (*GrpcService) UnsetReferences

func (c *GrpcService) UnsetReferences()

UnsetReferences method are unsets (clears) previously set references to dependent components.

type IGrpcServiceOverrides added in v1.1.0

type IGrpcServiceOverrides interface {
	Register()
}

type IRegisterable

type IRegisterable interface {
	// Perform required registration steps.
	Register()
}

IRegisterable is interface to perform on-demand registrations.

type InvokeComandMediator

type InvokeComandMediator struct {
	InvokeFunc func(ctx context.Context, request *grpcproto.InvokeRequest) (response *grpcproto.InvokeReply, err error)
}

InvokeComandMediator Helper class for implements invoke method in CommandableGrpc

func (*InvokeComandMediator) Invoke

func (c *InvokeComandMediator) Invoke(ctx context.Context, request *grpcproto.InvokeRequest) (response *grpcproto.InvokeReply, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL