SmallRye Stork, Stork, in short, is a Service Discovery and Client-Side Load Balancer framework.
-
Extensible service discovery mechanisms
-
Built-in support for Consul and Kubernetes
-
Customizable client load-balancing strategy
-
API and managed approaches
-
Quarkus integration, but can be used in any environment
-
Imperative and Reactive
Let’s imagine you use Consul. Consul stores the list of service instances you have and lets you locate them.
Stork bridges your application and Consul and lets you retrieve the services stored in Consul and select the most appropriate one:
Stork.initialize(); // (1)
Stork stork = Stork.getInstance(); // (2)
Service service = stork.getService("my-service"); // (3)
ServiceInstance instance = service.selectServiceInstance() // (4)
.await().atMost(Duration.ofSeconds(1));
String url = "http://" + instance.getHost() + instance.getPort(); // (5)
-
Initializes Stork - you need to do that only once.
-
Gets the Stork instance.
-
Gets the
Service
object formy-service
. -
Retrieves the service instance for
my-service
. This performs a lookup in Consul and a selection using a load-balancer. -
Builds your URL.
That example uses the programmatic API. When integrated into the framework, all these steps can be omitted, and you only need to configure the application:
stork.my-service.service-discovery.type=consul # (1)
stork.my-service.load-balancer.type=least-response-time # (2)
hello/mp-rest/url=stork://my-service/hello # (3)
-
Configures that the
my-service
service uses Consul as service discovery backend -
Configures the load balancer for
my-service
-
Uses the
stork
scheme and indicates which service is targeted. When accessed, it will select the service instance using Stork.
Check the contribution guide to get build and contribution instructions.
Stork is part of the SmallRye project. Red Hat sponsors the development of this project.