Skip to content

Consul Service Discovery#

Consul is a distributed, highly available, and data center aware solution to connect and configure applications across dynamic, distributed infrastructure. It’s often used as service discovery backend to register and locate the services composing your system. Consul makes it simple for services to register themselves and to discover other services via a DNS or HTTP interface. External services can be registered as well.

This page explains how Stork can use Consul to handle the service discovery and service registration.

Dependency#

First, you need to add the Stork Consul Service Discovery provider:

<dependency>
    <groupId>io.smallrye.stork</groupId>
    <artifactId>stork-service-discovery-consul</artifactId>
    <version>1.3.2</version>
</dependency>

Service discovery configuration#

For each service that should get the service instances from Consul, configure the service discovery type:

stork.my-service.service-discovery.type=consul
quarkus.stork.my-service.service-discovery.type=consul

Consul service discovery is configured with the following parameters:

Attribute Mandatory Default Value Description
consul-host No localhost The Consul host.
consul-port No 8500 The Consul port.
use-health-checks No true Whether to use health check.
application No The application name; if not defined Stork service name will be used.
refresh-period No 5M Service discovery cache refresh period.
secure No whether the connection with the service should be encrypted with TLS.

Service registration#

Stork also provides the ability to register services using Consul as backend.

Service registration configuration#

For each service that should register the service instances in Consul, configure the service discovery type:

stork.my-service.service-registrar.type=consul
quarkus.stork.my-service.service-registrar.type=consul

Consul service registrar is configured with the following parameters:

Attribute Mandatory Default Value Description
consul-host No localhost The Consul host.
consul-port No 8500 The Consul port.