SmallRye Stork, Stork in short, is an extensible Service Discovery and Client-Side Load Balancer implementation designed to work well with reactive libraries. Stork APIs use SmallRye Mutiny.
Stork maps service names to addresses.
Required ServiceDiscovery provides a list of addresses (as ServiceInstance)
for a given service name.
Optional LoadBalancer selects a single ServiceInstance for a call.
The project’s core aims to be vendor neutral. Aside from using Mutiny for the APIs, it has no dependencies. As such, it provides a universal abstraction of configuration and vendors can choose their own way of providing Stork configuration.
MicroProfile based frameworks can use MicroProfile Config to configure Stork. Below is an example snippet of such a configuration:
stork.my-service.service-discovery=consul
stork.my-service.service-discovery.some-service-discovery-property=property-value
stork.my-service.load-balancer=round-robin
stork.my-service.load-balancer.some-load-balancer-property=some-prop-value
stork.my-other-service.service-discovery=test-sd-1
stork.my-other-service.load-balancer=test-lb-1MicroProfile Config support for configuring SmallRye Stork is provided by the
smallrye-stork-microprofile artifact.
Client libraries would most often use a LoadBalancer to get a single address
for a call.
LoadBalancer for a service can be retrieved from Stork singleton:
LoadBalancer loadBalancer = Stork.getInstance().getLoadBalancer(serviceName);
Uni<ServiceInstance> serviceInstance = loadBalancer.selectServiceInstace();Alternatively, one can retrieve a stream of all available ServiceInstance’s for a
given service from `ServiceDiscovery:
ServiceDiscovery serviceDiscovery = Stork.getInstance().getServiceDiscovery(serviceName);
Multi<ServiceInstance> serviceInstances = serviceDiscovery.getServiceInstances();In Stork, extensibility is based on the [Service Provider Interface](https://docs.oracle.com/javase/tutorial/sound/SPI-intro.html) mechanism.
To add a custom configuration provider, create an implementation of ConfigProvider
and register it with the Service Provider Interfaces mechanism.
SmallRye Stork comes with MicroProfile Config based configuration provider.
To use it, add smallrye-stork-microprofile to your project.
To implement a custom service discovery for Stork, implement the ServiceDiscoveryProvider
interface and register it with the Service Provider Interface mechanism.
Please note that the ServiceDiscovery implementation must be non-blocking.
The following are required to build the project:
-
JDK 11+
-
Maven 3.6.3+
IntelliJ IDEA may think that the project uses
Java 8. To fix it, go to Maven → Profiles and deselect
include-jdk-misc and compile-java8-release-flag
profiles.
We may have a couple of modes for service discovery refresh
-
server push - we keep a list of service instances and always return the list until a notification comes that we need to update it
-
eager refresh - refresh service instances on an interval basis
-
lazy refresh - when invoked and configured interval since the last refresh happened, refetch the data before return the result
-
it may be good to have a separate option to return the old data until the refresh is complete
-