pip_services3_grpc.clients.CommandableGrpcClient module

class pip_services3_grpc.clients.CommandableGrpcClient.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 it

  • options: - 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