pip_services3_grpc.clients package
Submodules
Module contents
-
class
pip_services3_grpc.clients.
CommandableGrpcClient
(name: str) Bases:
pip_services3_grpc.clients.GrpcClient.GrpcClient
Abstract client that calls commandable GRPC service.
Commandable services are generated automatically for
ICommandable
. Each command is exposed as Invoke method that receives all parameters as args.- ### Configuration parameters ###
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 itoptions: - retries: number of retries (default: 3) - connect_timeout: connection timeout in milliseconds (default: 10 sec) - timeout: invocation timeout in milliseconds (default: 10 sec)
- ### 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
class MyCommandableGrpcClient(CommandableGrpcClient, IMyClient): def __init__(self): super().__init__('my_data') ... def get_data(self, correlation_id, id): return self.call_command( "get_data", correlation_id, { 'id': id } ) client = new MyCommandableGrpcClient() client.configure(ConfigParams.from_tuples( "connection.protocol", "http", "connection.host", "localhost", "connection.port", 8080 )) result = client.get_data("123", "1")
-
call_command
(name: str, correlation_id: Optional[str], params: dict) → Any Calls a remote method via GRPC commadable protocol. The call is made via Invoke method and all parameters are sent in args object. The complete route to remote method is defined as serviceName + ‘.’ + name.
- Parameters
name – a name of the command to call.
correlation_id – (optional) transaction id to trace execution through call chain.
params – command parameters.
- Returns
Future that receives result
-
class
pip_services3_grpc.clients.
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.