Package emissary.grpc

Class GrpcRoutingPlace

  • All Implemented Interfaces:
    IGrpcRoutingPlace, IServiceProviderPlace, ServiceProviderPlaceMBean
    Direct Known Subclasses:
    GrpcConnectionPlace, GrpcSampleServicePlace

    public abstract class GrpcRoutingPlace
    extends ServiceProviderPlace
    implements IGrpcRoutingPlace
    Place for processing data using gRPC connections to external services. Supports multiple end-points with shared configurations, where each endpoint is identified by a given target ID.

    Configuration Keys:

    • GRPC_HOST_{Target-ID} - gRPC service hostname or DNS target, where Target-ID is the unique identifier for the given host:port
    • GRPC_PORT_{Target-ID} - gRPC service port, where Target-ID is the unique identifier for the given host:port
    • See ConnectionFactory for supported pooling and gRPC channel configuration keys and defaults.
    • See RetryHandler for supported retry configuration keys and defaults.
    • Method Detail

      • getHostnameConfigs

        protected Map<String,​String> getHostnameConfigs()
      • getPortNumberConfigs

        protected Map<String,​Integer> getPortNumberConfigs()
      • validateConnection

        protected abstract boolean validateConnection​(io.grpc.ManagedChannel managedChannel)
        Validates whether a given ManagedChannel is capable of successfully communicating with its associated gRPC server.
        Parameters:
        managedChannel - the gRPC channel to validate
        Returns:
        true if the channel is healthy and the server responds successfully, else false
      • passivateConnection

        protected void passivateConnection​(io.grpc.ManagedChannel managedChannel)
        Called after a gRPC call to clean up the channel. No-op by default, since gRPC channels are designed to remain ready for reuse. Override this if using a stub that requires channels be reset or cleared between uses.
        Parameters:
        managedChannel - the gRPC channel to clean up
      • invokeGrpc

        protected <Q extends com.google.protobuf.GeneratedMessageV3,​R extends com.google.protobuf.GeneratedMessageV3,​S extends io.grpc.stub.AbstractBlockingStub<S>> R invokeGrpc​(String targetId,
                                                                                                                                                                                              Function<io.grpc.ManagedChannel,​S> stubFactory,
                                                                                                                                                                                              BiFunction<S,​Q,​R> callLogic,
                                                                                                                                                                                              Q request)
        Wrapper method for GrpcInvoker.invoke(ObjectPool, Function, BiFunction, GeneratedMessageV3) that executes a unary gRPC call to a given endpoint.
        Type Parameters:
        Q - the protobuf request type
        R - the protobuf response type
        S - the gRPC stub type
        Parameters:
        targetId - the identifier used in the configs for the given gRPC endpoint
        stubFactory - function that creates the appropriate gRPC stub from a ManagedChannel
        callLogic - function that performs the actual gRPC call using the stub and request
        request - the protobuf request message to send
        Returns:
        the response returned by the gRPC call
      • invokeGrpcAsync

        protected <Q extends com.google.protobuf.GeneratedMessageV3,​R extends com.google.protobuf.GeneratedMessageV3,​S extends io.grpc.stub.AbstractFutureStub<S>> CompletableFuture<R> invokeGrpcAsync​(String targetId,
                                                                                                                                                                                                                    Function<io.grpc.ManagedChannel,​S> stubFactory,
                                                                                                                                                                                                                    BiFunction<S,​Q,​com.google.common.util.concurrent.ListenableFuture<R>> callLogic,
                                                                                                                                                                                                                    Q request)
        Wrapper method for GrpcInvoker.invokeAsync(ObjectPool, Function, BiFunction, GeneratedMessageV3) that executes a unary gRPC call to a given endpoint and returns a future.
        Type Parameters:
        Q - the protobuf request type
        R - the protobuf response type
        S - the gRPC stub type
        Parameters:
        targetId - the identifier used in the configs for the given gRPC endpoint
        stubFactory - function that creates the appropriate gRPC stub from a ManagedChannel
        callLogic - function that performs the actual gRPC call using the stub and request
        request - the protobuf request message to send
        Returns:
        the future that waits for the response returned by the gRPC call
      • getHostname

        public String getHostname​(String targetId)
      • getPortNumber

        public int getPortNumber​(String targetId)
      • tableLookup

        protected <T> T tableLookup​(Map<String,​T> table,
                                    String targetId)