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

    Fields
    Modifier and Type
    Field
    Description
    protected io.grpc.Channel
     
    protected org.pipservices4.config.connect.HttpConnectionResolver
    The connection resolver.
    protected long
    The connection timeout in milliseconds.
    protected org.pipservices4.observability.count.CompositeCounters
    The performance counters.
    protected org.pipservices4.observability.log.CompositeLogger
    The logger.
    protected org.pipservices4.components.config.ConfigParams
    The configuration options.
    protected long
    The invocation timeout in milliseconds.
    protected org.pipservices4.observability.trace.CompositeTracer
    The tracer.
    protected String
    The remote service uri which is calculated on open.
  • Constructor Summary

    Constructors
    Constructor
    Description
    GrpcClient(io.grpc.ServiceDescriptor serviceDescriptor)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected <TRequest, TResponse>
    TResponse
    call(String methodName, org.pipservices4.components.context.IContext context, TRequest request)
    Calls a remote method via GRPC protocol.
    void
    close(org.pipservices4.components.context.IContext context)
    Closes component and frees used resources.
    void
    configure(org.pipservices4.components.config.ConfigParams config)
    Configures component by passing configuration parameters.
    protected org.pipservices4.rpc.trace.InstrumentTiming
    instrument(org.pipservices4.components.context.IContext context, String name)
    Adds instrumentation to log calls and measure call time.
    boolean
    Checks if the component is opened.
    void
    open(org.pipservices4.components.context.IContext context)
    Opens the component.
    void
    setReferences(org.pipservices4.components.refer.IReferences references)
    Sets references to dependent components.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • _channel

      protected io.grpc.Channel _channel
    • _connectionResolver

      protected org.pipservices4.config.connect.HttpConnectionResolver _connectionResolver
      The connection resolver.
    • _logger

      protected org.pipservices4.observability.log.CompositeLogger _logger
      The logger.
    • _counters

      protected org.pipservices4.observability.count.CompositeCounters _counters
      The performance counters.
    • _tracer

      protected org.pipservices4.observability.trace.CompositeTracer _tracer
      The tracer.
    • _options

      protected org.pipservices4.components.config.ConfigParams _options
      The configuration options.
    • _connectTimeout

      protected long _connectTimeout
      The connection timeout in milliseconds.
    • _timeout

      protected long _timeout
      The invocation timeout in milliseconds.
    • _uri

      protected String _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:
      configure in interface org.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:
      setReferences in interface org.pipservices4.components.refer.IReferenceable
      Parameters:
      references - references to locate the component dependencies.
      Throws:
      org.pipservices4.components.refer.ReferenceException
      org.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:
      isOpen in interface org.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:
      open in interface org.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:
      close in interface org.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 called
      context - (optional) a context to trace execution through call chain.
      request - (optional) request object.
      Returns:
      the received result.