Class DynamicGrpcClientFactory

java.lang.Object
ai.pipestream.dynamic.grpc.client.DynamicGrpcClientFactory
All Implemented Interfaces:
GrpcClientFactory

@ApplicationScoped public class DynamicGrpcClientFactory extends Object implements GrpcClientFactory
Factory for creating Mutiny gRPC clients using dynamic service discovery. This factory ensures the service is defined in Stork, discovers instances, obtains a Channel from ChannelManager, and produces Mutiny stubs on demand.
  • Constructor Details

    • DynamicGrpcClientFactory

      public DynamicGrpcClientFactory()
      Default constructor for CDI frameworks.
  • Method Details

    • getClient

      public <T extends io.quarkus.grpc.MutinyStub> io.smallrye.mutiny.Uni<T> getClient(String serviceName, Function<io.grpc.Channel,T> stubCreator)
      Get a typed Mutiny stub using a method reference (zero reflection).
      Specified by:
      getClient in interface GrpcClientFactory
      Type Parameters:
      T - The Mutiny stub type (must extend MutinyStub)
      Parameters:
      serviceName - The logical service name for discovery
      stubCreator - Method reference to create stub (e.g., MutinyFooServiceGrpc::newMutinyStub)
      Returns:
      A Uni emitting the typed Stub
    • getChannel

      public io.smallrye.mutiny.Uni<io.grpc.Channel> getChannel(String serviceName)
      Description copied from interface: GrpcClientFactory
      Get a raw Channel for advanced use cases.
      Specified by:
      getChannel in interface GrpcClientFactory
      Parameters:
      serviceName - The logical service name for discovery
      Returns:
      A Uni emitting the Channel
    • getActiveServiceCount

      public int getActiveServiceCount()
      Description copied from interface: GrpcClientFactory
      Get the number of active service connections being managed.
      Specified by:
      getActiveServiceCount in interface GrpcClientFactory
    • evictChannel

      public void evictChannel(String serviceName)
      Description copied from interface: GrpcClientFactory
      Evict (close) a cached channel for a service to force reconnection.
      Specified by:
      evictChannel in interface GrpcClientFactory
    • getCacheStats

      public String getCacheStats()
      Description copied from interface: GrpcClientFactory
      Get cache statistics for debugging and monitoring.
      Specified by:
      getCacheStats in interface GrpcClientFactory