Service Discovery enables the ability for Microservices to find each other without necessarily knowing the physical location or IP address of associated services.
There are many ways Service Discovery can be implemented, including:
Manually implement Service Discovery using DNS without requiring a third party tool or component.
Delegate the work to a container runtime, such as .
Consul
To include Service Discovery in your application simply the first step is to add the dependency to your application:
The discovery-client
dependency provides implementations of the DiscoveryClient interface.
The is fairly simple and provides two main entry points:
DiscoveryClient.getInstances(java.lang.String) - Returns all the objects for a given service ID
Both methods return Publisher instances since the operation to retrieve service ID information may result in a blocking network call depending on the underlying implementation.
If you are using Micronaut’s cache module, the default implementation of the interface is which merges all other DiscoveryClient
beans into a single bean and provides caching of the results of the methods. The default behaviour is to cache for 30 seconds. This cache can be disabled in application configuration:
Disabling the Discovery Client Cache
Alternatively you can alter the cache’s expiration policy:
See the DiscoveryClientCacheConfiguration class for available configuration options.