GrpcService mixin
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 fromIDiscovery
protocol
: connection protocol: http or httpshost
: host name or IP addressport
: port numberuri
: resource URI or connection string with all parameters in it
credential
- the HTTPS credentials:ssl_key_file
: the SSL private key in PEMssl_crt_file
: the SSL certificate in PEMssl_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
- Object
- Implemented by
Constructors
Properties
- counters → CompositeCounters
-
The performance counters.
final
- dependencyResolver → DependencyResolver
-
The dependency resolver.
final
- endpoint ↔ GrpcEndpoint
-
The GRPC endpoint that exposes this service.
read / write
- logger → CompositeLogger
-
The logger.
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
-
close(
String correlationId) → Future - Closes component and frees used resources. [...]
-
configure(
ConfigParams config) → void - Configures component by passing configuration parameters. [...]
-
instrument(
String correlationId String name) → Timing - Adds instrumentation to log calls and measure call time. It returns a Timing object that is used to end the time measurement. [...]
-
instrumentError(
String correlationId, String name, dynamic err, [ bool reerror = false ]) → void - Adds instrumentation to error handling. [...]
-
isOpen(
) → bool - Checks if the component is opened. [...]
-
open(
String correlationId) → Future - Opens the component. [...]
-
register(
) → void - Registers all service routes in Grpc endpoint. [...]
-
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 [...]
-
setReferences(
IReferences references) → void - Sets references to dependent components. [...]
-
unsetReferences(
) → void - Unsets (clears) previously set references to dependent components.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a non-existent method or property is accessed. [...]
inherited
-
toString(
) → String -
Returns a string representation of this object.
inherited
Operators
-
operator ==(
dynamic other) → bool -
The equality operator. [...]
inherited