Thanks to visit codestin.com
Credit goes to github.com

Skip to content

geoand/smallrye-stork

 
 

Repository files navigation

badge Quality Gate Status License Maven

SmallRye Stork

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.

Configuring user applications

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-1

MicroProfile Config support for configuring SmallRye Stork is provided by the smallrye-stork-microprofile artifact.

Integrating client libraries with Stork

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();

Extending the functionality

In Stork, extensibility is based on the [Service Provider Interface](https://docs.oracle.com/javase/tutorial/sound/SPI-intro.html) mechanism.

Configuration provider

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.

Service Discovery

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.

Load Balancer

To implement a custom load balancer for Stork, implement the LoadBalancerProvider interface and register it with the Service Provider Interface mechanism.

Please note that the LoadBalancer implementation, similarly to ServiceDiscovery must be non-blocking.

Contributing

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.

TODOs

Service Discovery refresh

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

Gathering statistics

For smart Load Balancers we need statistics for calls.

Scheduling

For eager refresh, it may be good to provide a "helper" - a facade for scheduling tasks. Such a facade could have bindings for Vert.x, Quartz, etc.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%