Package org.pipservices4.grpc.clients
Class GrpcClient
java.lang.Object
org.pipservices4.grpc.clients.GrpcClient
- 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:
CommandableGrpcClient,TestGrpcClient
public class GrpcClient
extends Object
implements org.pipservices4.components.run.IOpenable, org.pipservices4.components.config.IConfigurable, org.pipservices4.components.refer.IReferenceable
Abstract client that calls remove endpoints using GRPC protocol.
### 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
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected io.grpc.Channelprotected org.pipservices4.config.connect.HttpConnectionResolverThe connection resolver.protected longThe connection timeout in milliseconds.protected org.pipservices4.observability.count.CompositeCountersThe performance counters.protected org.pipservices4.observability.log.CompositeLoggerThe logger.protected org.pipservices4.components.config.ConfigParamsThe configuration options.protected longThe invocation timeout in milliseconds.protected org.pipservices4.observability.trace.CompositeTracerThe tracer.protected StringThe remote service uri which is calculated on open. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected <TRequest,TResponse>
TResponseCalls a remote method via GRPC protocol.voidclose(org.pipservices4.components.context.IContext context) Closes component and frees used resources.voidconfigure(org.pipservices4.components.config.ConfigParams config) Configures component by passing configuration parameters.protected org.pipservices4.rpc.trace.InstrumentTiminginstrument(org.pipservices4.components.context.IContext context, String name) Adds instrumentation to log calls and measure call time.booleanisOpen()Checks if the component is opened.voidopen(org.pipservices4.components.context.IContext context) Opens the component.voidsetReferences(org.pipservices4.components.refer.IReferences references) Sets references to dependent components.
-
Field Details
-
_channel
protected io.grpc.Channel _channel -
_connectionResolver
protected org.pipservices4.config.connect.HttpConnectionResolver _connectionResolverThe connection resolver. -
_logger
protected org.pipservices4.observability.log.CompositeLogger _loggerThe logger. -
_counters
protected org.pipservices4.observability.count.CompositeCounters _countersThe performance counters. -
_tracer
protected org.pipservices4.observability.trace.CompositeTracer _tracerThe tracer. -
_options
protected org.pipservices4.components.config.ConfigParams _optionsThe configuration options. -
_connectTimeout
protected long _connectTimeoutThe connection timeout in milliseconds. -
_timeout
protected long _timeoutThe invocation timeout in milliseconds. -
_uri
The remote service uri which is calculated on open.
-
-
Constructor Details
-
GrpcClient
public GrpcClient(io.grpc.ServiceDescriptor serviceDescriptor)
-
-
Method Details
-
configure
public void configure(org.pipservices4.components.config.ConfigParams config) throws org.pipservices4.commons.errors.ConfigException Configures component by passing configuration parameters.- Specified by:
configurein interfaceorg.pipservices4.components.config.IConfigurable- Parameters:
config- configuration parameters to be set.- Throws:
org.pipservices4.commons.errors.ConfigException
-
setReferences
public void setReferences(org.pipservices4.components.refer.IReferences references) throws org.pipservices4.components.refer.ReferenceException, org.pipservices4.commons.errors.ConfigException Sets references to dependent components.- Specified by:
setReferencesin interfaceorg.pipservices4.components.refer.IReferenceable- Parameters:
references- references to locate the component dependencies.- Throws:
org.pipservices4.components.refer.ReferenceExceptionorg.pipservices4.commons.errors.ConfigException
-
instrument
protected org.pipservices4.rpc.trace.InstrumentTiming instrument(org.pipservices4.components.context.IContext context, String name) Adds instrumentation to log calls and measure call time. It returns a CounterTiming object that is used to end the time measurement.- Parameters:
context- (optional) a context to trace execution through call chain.name- a method name.- Returns:
- CounterTiming object to end the time measurement.
-
isOpen
public boolean isOpen()Checks if the component is opened.- Specified by:
isOpenin interfaceorg.pipservices4.components.run.IOpenable- Returns:
- true if the component has been opened and false otherwise.
-
open
public void open(org.pipservices4.components.context.IContext context) throws org.pipservices4.commons.errors.ApplicationException Opens the component.- Specified by:
openin interfaceorg.pipservices4.components.run.IOpenable- Parameters:
context- (optional) a context to trace execution through call chain.- Throws:
org.pipservices4.commons.errors.ApplicationException
-
close
public void close(org.pipservices4.components.context.IContext context) throws org.pipservices4.commons.errors.ApplicationException Closes component and frees used resources.- Specified by:
closein interfaceorg.pipservices4.components.run.IClosable- Parameters:
context- (optional) a context to trace execution through call chain.- Throws:
org.pipservices4.commons.errors.ApplicationException
-
call
protected <TRequest,TResponse> TResponse call(String methodName, org.pipservices4.components.context.IContext context, TRequest request) Calls a remote method via GRPC protocol.- Parameters:
methodName- a method name to calledcontext- (optional) a context to trace execution through call chain.request- (optional) request object.- Returns:
- the received result.
-