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 from IDiscoveryprotocol
: 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');
- Implemented types
- Mixin Applications
Properties
- counters → CompositeCounters
-
The performance counters.
final
- dependencyResolver → DependencyResolver
-
The dependency resolver.
final
- endpoint ↔ GrpcEndpoint?
-
The GRPC endpoint that exposes this service.
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- logger → CompositeLogger
-
The logger.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- serviceName ← String
-
Sets service name
no getter
- tracer → CompositeTracer
-
The tracer.
final
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) → 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.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
open(
String? correlationId) → Future - Opens the component.
-
register(
) → void -
Registers all service routes in Grpc endpoint.
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
-
setReferences(
IReferences references) → void - Sets references to dependent components.
-
toString(
) → String -
A string representation of this object.
inherited
-
unsetReferences(
) → void - Unsets (clears) previously set references to dependent components.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited