GrpcService mixin Null safety

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 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

class MyGrpcService extends MyDataGrpcServiceBase with GrpcService {
    IMyController _controller;
   ...
   MyGrpcService() {
      serviceName = '.. service name ...';
      dependencyResolver.put(
          'controller',
          Descriptor('mygroup','controller','*','*','1.0')
      );
   }

   void setReferences(IReferences references) {
      base.setReferences(references);
      _controller = dependencyResolver.getRequired<IMyController>('controller');
   }

   public register() {
       registerInterceptor(_incrementNumberOfCalls);
       registerService(this);
    }
      Future<grpcService.MyData> getMyData(ServiceCall call, grpcService.MyDataIdRequest request) async{
           var correlationId = request.correlationId;
           var id = request.id;
           var result = await_controller.getMyData(correlationId, id);
           var item = grpcService.MyData();
           // ... convert MyData -> grpcService.MyData
           return item;
       });
       ...
   }
}

var service = MyGrpcService();
service.configure(ConfigParams.fromTuples([
    'connection.protocol', 'http',
    'connection.host', 'localhost',
    'connection.port', 8080
]));
service.setReferences(References.fromTuples([
    Descriptor('mygroup','controller','default','default','1.0'), controller
]));

await service.open('123')
print ('The GRPC service is running on port 8080');
Superclass Constraints
Implements
Implemented by

Constructors

GrpcService()

Properties

endpoint GrpcEndpoint?
The GRPC endpoint that exposes this service.
read / write
dependencyResolver DependencyResolver
The dependency resolver.
final
logger CompositeLogger
The logger.
final
counters CompositeCounters
The performance counters.
final
tracer → CompositeTracer
The tracer.
final
serviceName String
Sets service name [...]
write-only
hashCode int
The hash code for this object. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

configure(ConfigParams config) → void
Configures component by passing configuration parameters. [...]
override
setReferences(IReferences references) → void
Sets references to dependent components. [...]
override
unsetReferences() → void
Unsets (clears) previously set references to dependent components.
override
instrument(String? correlationId, String name) InstrumentTiming
Adds instrumentation to log calls and measure call time. It returns a Timing object that is used to end the time measurement. [...]
isOpen() bool
Adds instrumentation to error handling. [...]
override
open(String? correlationId) Future
Opens the component. [...]
override
close(String? correlationId) Future
Closes component and frees used resources. [...]
override
registerCommadableMethod(String method, Schema? schema, Future action(String? correlationId, Parameters args)) → void
Registers a commandable method in this objects GRPC server (service) by the given name., [...]
registerInterceptor(Interceptor action) → void
Registers a middleware for methods in GRPC endpoint. [...]
registerService(Service implementation) → void
Registers a service with related implementation [...]
register() → void
Registers all service routes in Grpc endpoint. [...]
override
toString() String
A string representation of this object. [...]
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited

Operators

operator ==(Object other) bool
The equality operator. [...]
inherited