Service Discovery

In a Microservice architecture services need to discover each other in a decoupled manner that is independent of the service discovery mechanism.

Micronaut features a Service Discovery abstraction that allows service discovery to be backed onto different implementations including Kubernetes, HashiCorp Consul, Eureka and more.

The original MuShop application featured extensive handcrafted service discovery code in both the Spring application:

And Node/Express JavaScript API:

By migrating the code to Micronaut all this code could be deleted and instead encapsulated by the defining of a simple service ID and declarative client interfaces:

@Client(id = "mushop-catalogue", path = "/catalogue")
public interface CatalogueClient {
    @Get("/{id}")
    Maybe<Product> getItem(String id);
}

Using the service ID Micronaut provides client side lookup and load balancing and the target service to invoke is abstracted such that it can be found via explicit declaration in configuration (for example when working locally):

micronaut:
	http:
		services:
			mushop-catalogue:
				url: http://localhost:8082

Or automatically via Micronaut’s integration with Kubernetes when deployed to a cluster.