Class Service


  • public class Service
    extends Object
    Represents a Service.

    This container gives you access to the service instances and to the selected service instance.

    • Constructor Detail

      • Service

        public Service​(String serviceName,
                       String serviceSelectionType,
                       String serviceDiscoveryType,
                       ObservationCollector collector,
                       LoadBalancer loadBalancer,
                       ServiceDiscovery serviceDiscovery,
                       ServiceRegistrar<?> serviceRegistrar,
                       boolean requiresStrictRecording)
        Creates a new Service.
        Parameters:
        serviceName - the name, must not be null, must not be blank
        serviceDiscoveryType - the type of the service discovery (for observability purpose)
        serviceSelectionType - the type of the service selection (for observability purpose)
        collector - the observation collector, must not be null
        loadBalancer - the load balancer, can be null
        serviceDiscovery - the service discovery, must not be null
        serviceRegistrar - the service registrar, can be null
        requiresStrictRecording - whether strict recording must be enabled
    • Method Detail

      • selectInstance

        public io.smallrye.mutiny.Uni<ServiceInstance> selectInstance()
        Selects a service instance.

        The selection looks for the service instances and select the one to use using the load balancer.

        Note: this method doesn't record a start of an operation using this load balancer and does not synchronize load balancer invocations even if the load balancer is not thread safe

        Returns:
        a Uni with a ServiceInstance, or with NoServiceInstanceFoundException if the load balancer failed to find a service instance capable of handling a call
      • selectInstance

        public ServiceInstance selectInstance​(Collection<ServiceInstance> instances)
        Using the underlying load balancer, select a service instance from the collection of service instances.

        Note: this method doesn't record a start of an operation using this load balancer and does not synchronize load balancer invocations even if the load balancer is not thread safe

        Parameters:
        instances - collection of instances
        Returns:
        a ServiceInstance, or with NoServiceInstanceFoundException if the load balancer failed to find a service instance capable of handling a call
        Throws:
        NoServiceInstanceFoundException - if all the instances are nto
      • selectInstanceAndRecordStart

        public io.smallrye.mutiny.Uni<ServiceInstance> selectInstanceAndRecordStart​(boolean measureTime)
        Selects a service instance and records a start of an operation using the instance

        The selection looks for the service instances and select the one to use using the load balancer.

        Parameters:
        measureTime - whether the operation for which the operation is chosen records time (will call ServiceInstance.recordReply())
        Returns:
        a Uni with a ServiceInstance, or with NoServiceInstanceFoundException if the load balancer failed to find a service instance capable of handling a call
        See Also:
        LoadBalancer.requiresStrictRecording()
      • getLoadBalancer

        public LoadBalancer getLoadBalancer()
        Get the underlying load balancer instance.
        Returns:
        load balancer
      • getServiceDiscovery

        public ServiceDiscovery getServiceDiscovery()
        Get the underlying service discovery
        Returns:
        service discovery
      • getServiceRegistrar

        public ServiceRegistrar getServiceRegistrar()
        Get the underlying service registrar
        Returns:
        service registrar
      • getServiceName

        public String getServiceName()
        Returns:
        the service name.