Auto Registering with Consul
To register a Micronaut application with Consul simply add the necessary ConsulConfiguration. A minimal example can be seen below:
Auto Registering with Consul (application.yml)
micronaut:
application:
name: hello-world
consul:
client:
registration:
enabled: true
defaultZone: "${CONSUL_HOST:localhost}:${CONSUL_PORT:8500}"
Using the Micronaut CLI you can quickly create a new service setup with Consul using: mn create-app my-app —features discovery-consul |
The consul.client.defaultZone
settings accepts a list of Consul servers to be used by default.
You could also simply set consul.client.host and consul.client.port , however ConsulConfiguration allows you specify per zone discovery services for the purpose load balancing. A zone maps onto a AWS availability zone or a Google Cloud zone. |
By default registering with Consul is disabled hence you should set consul.client.registration.enabled
to true
. Note that you may wish to do this only in your production configuration.
Running multiple instances of a service may require an additional configuration param. See below. |
If you are running the same applications on the same port across different servers it is important to set the micronaut.application.instance.id
property or you will experience instance registration collision.
micronaut:
application:
name: hello-world
instance:
id: ${random.shortuuid}