Package org.pipservices4.grpc.clients
Class CommandableGrpcClient
java.lang.Object
org.pipservices4.grpc.clients.GrpcClient
org.pipservices4.grpc.clients.CommandableGrpcClient
- All Implemented Interfaces:
org.pipservices4.components.config.IConfigurable,org.pipservices4.components.refer.IReferenceable,org.pipservices4.components.run.IClosable,org.pipservices4.components.run.IOpenable
- Direct Known Subclasses:
TestCommandableGrpcClient
Abstract client that calls commandable GRPC service.
Commandable services are generated automatically for ICommandable objects.
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
### Example ###
class MyCommandableGrpcClient extends CommandableGrpcClient implements IMyClient {
public MyCommandableGrpcClient() {
super("mydata");
}
// ...
@Override
public MyData getData(IContext context, String id) {
return this.callCommand(MyData.class,
"get_data",
context,
Map.of("id", id)
);
}
public static void main(String[] args) throws ConfigException {
var client = new MyCommandableGrpcClient();
client.configure(ConfigParams.fromTuples(
"connection.protocol", "http",
"connection.host", "localhost",
"connection.port", 8080
));
var result = client.getData("123", "1");
}
}
-
Field Summary
FieldsFields inherited from class org.pipservices4.grpc.clients.GrpcClient
_channel, _connectionResolver, _connectTimeout, _counters, _logger, _options, _timeout, _tracer, _uri -
Constructor Summary
ConstructorsConstructorDescriptionCommandableGrpcClient(String name) Create new instance of the commandable client -
Method Summary
Modifier and TypeMethodDescriptionprotected <T> TcallCommand(Class<T> returnType, String name, org.pipservices4.components.context.IContext context, Object params) Calls a remote method via GRPC commadable protocol.Methods inherited from class org.pipservices4.grpc.clients.GrpcClient
call, close, configure, instrument, isOpen, open, setReferences
-
Field Details
-
_name
The service name
-
-
Constructor Details
-
CommandableGrpcClient
Create new instance of the commandable client- Parameters:
name- The service name
-
-
Method Details
-
callCommand
protected <T> T callCommand(Class<T> returnType, String name, org.pipservices4.components.context.IContext context, Object params) 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:
returnType- generic type of the return objectname- a name of the command to call.context- (optional) a context to trace execution through call chain.params- command parameters.- Returns:
- the received result.
-