pip_services3_grpc.services.GrpcService module
-
class
pip_services3_grpc.services.GrpcService.
GrpcService
(service_name: str = None) Bases:
pip_services3_commons.run.IOpenable.IOpenable
,pip_services3_commons.config.IConfigurable.IConfigurable
,pip_services3_grpc.services.IRegisterable.IRegisterable
,pip_services3_commons.refer.IUnreferenceable.IUnreferenceable
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 itcredential - 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
class MyGrpcService(GrpcService, my_data_pb2_grpc.MyDataServicer): __controller: IMyController ... def __init__(self): suoer().__init__('.. service name ...') self._dependency_resolver.put( "controller", Descriptor("mygroup","controller","*","*","1.0") ) def add_servicer_to_server(self, server): my_data_pb2_grpc.add_MyDataServicer_to_server(self, server) def set_references(self, references): super().set_references(references) self._controller = this._dependency_resolver.get_required("controller") def __number_of_calls_interceptor(self, request: InvokeRequest, context: ServicerContext, next: Callable[[InvokeRequest, ServicerContext], Any]) -> Any: self.__number_of_calls += 1 return next(request, context) def __method(request: InvokeRequest, context: ServicerContext): correlationId = request.correlationId id = request.id return self._controller.get_my_data(correlationId, id) def register(self): self._register_interceptor(self.__number_of_calls_interceptor) self._register_method("get_mydata", None, method) self._register_service(self) ... service = MyGrpcService() service.configure(ConfigParams.from_tuples( "connection.protocol", "http", "connection.host", "localhost", "connection.port", 8080 )) service.set_references(References.from_tuples( Descriptor("mygroup","controller","default","default","1.0"), controller )) service.open("123")
-
close
(correlation_id: Optional[str]) Closes component and frees used resources.
- Parameters
correlation_id – (optional) transaction id to trace execution through call chain.
-
configure
(config: pip_services3_commons.config.ConfigParams.ConfigParams) Configures component by passing configuration parameters. :param config: configuration parameters to be set.
-
is_open
() → bool Checks if the component is opened.
- Returns
true if the component has been opened and false otherwise.
-
open
(correlation_id: Optional[str]) Opens the component.
- Parameters
correlation_id – (optional) transaction id to trace execution through call chain.
-
abstract
register
() Registers all service routes in Grpc endpoint. This method is called by the service and must be overriden in child classes.
-
set_references
(references: pip_services3_commons.refer.IReferences.IReferences) Sets references to this 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.
-
unset_references
() Unsets (clears) previously set references to dependent components.