pip_services3_grpc.clients.GrpcClient module
-
class
pip_services3_grpc.clients.GrpcClient.
GrpcClient
(service_client: Any, client_name: str = None) Bases:
pip_services3_commons.run.IOpenable.IOpenable
,pip_services3_commons.refer.IReferenceable.IReferenceable
,pip_services3_commons.config.IConfigurable.IConfigurable
Abstract client that calls remove endpoints using GRPC protocol.
- ### Configuration parameters ###
connection(s): - discovery_key: (optional) a key to retrieve the connection from
link()
- 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 itoptions: - retries: number of retries (default: 3) - connect_timeout: connection timeout in milliseconds (default: 10 sec) - timeout: invocation timeout in milliseconds (default: 10 sec)
class MyGrpcClient(GrpcClient, IMyClient): def __init__(self): super().__init__(my_data_pb2_grpc.MyDataStub, 'my_data_v1') ... def get_data(self, correlation_id, id ): timing = self.instrument(correlation_id, 'myclient.get_data') result = self._call("get_data", correlation_id, { id: id }) timing.end_timing() return result ... client = MyGrpcClient() client.configure(ConfigParams.from_tuples( "connection.protocol", "http", "connection.host", "localhost", "connection.port", 8080 )) result = client.get_data("123", "1")
-
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.
- Parameters
config – configuration parameters to be set.
-
is_open
() → bool Checks if the component is opened.
- Returns
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.
-
set_references
(references: pip_services3_commons.refer.IReferences.IReferences) Sets references to dependent components.
- Parameters
references – references to locate the component dependencies.