Integrating AWS Service Discovery in Micronaut Application

Integrating AWS Service Discovery into Micronaut can greatly improve the scalability and reliability of your microservice-based applications. AWS Service Discovery allows you to automatically register and discover services in your environment, making it easier to manage and track changes to your infrastructure. In this blog post, we’ll explore the steps required to integrate AWS Service Discovery into a Micronaut application. Before that let’s try to understand few key concepts.

  1. What are namespace in AWS?
  2. What are AWS Service Discovery and it’s uses
  3. Service Discovery in Micronaut
  4. Implementation

Namespace:

A namespace is a logical container for a group of services in AWS Service Discovery. A namespace provides a way to organize and group services within a single environment, making it easier to manage and track changes to your infrastructure.

Each namespace is isolated from other namespaces and services within the same environment. This means that services registered in one namespace are not accessible from another namespace. This allows you to organize services based on their functional or organizational characteristics, making it easier to manage and monitor your environment.

For example, you could create separate namespaces for development, testing, and production environments, or for different parts of your application such as front-end, back-end, and database services.

AWS Service Discovery provides support for multiple namespaces within the same environment, making it easy to manage and scale your infrastructure as your needs change over time. By using namespaces, you can easily isolate and manage services, simplify your infrastructure, and improve the reliability and scalability of your microservice-based applications.

AWS Service Discovery:

AWS Service Discovery provides a way for services to discover and connect to other services within a microservice-based application. The following is a list of services that can be registered with AWS Service Discovery:

  1. HTTP/HTTPS services: Services that are accessible via the HTTP or HTTPS protocols can be registered with AWS Service Discovery and made discoverable to other services.
  2. Custom services: Services that use custom protocols can also be registered with AWS Service Discovery, allowing them to be discoverable to other services in the environment.
  3. AWS resources: AWS resources such as EC2 instances, Lambda functions, and ECS tasks can be registered with AWS Service Discovery and made discoverable to other services in the environment.
  4. External services: External services that are not hosted on AWS can also be registered with AWS Service Discovery and made discoverable to services in the environment.

By using AWS Service Discovery, services can discover and connect to each other automatically and dynamically, reducing the need for manual configuration and improving the reliability and scalability of your microservice-based applications.

Service Discovery in Micronaut

Micronaut supports multiple types of service discovery, including service discovery via a Consul or Eureka server, as well as custom implementations. You can choose the type of service discovery that best fits your requirements, and Micronaut will handle the discovery process automatically for you.

https://micronaut-projects.github.io/micronaut-discovery-client/latest/guide/

By using Micronaut’s built-in service discovery mechanism, you can simplify the process of connecting microservices and improve the reliability and scalability of your microservices-based applications. 

Implementation.

Before starting the implementation, here are the pre requisite

  1. You have already setup the namespace and services
  2. You have a micronaut application running in this namespace
  3. The application should have credentials to connect aws or IAM to the services to call service discovery.

Micronaut provides discovery client to resolve services

Import libraries (AWS discovery, Micronaut Discovery)

implementation('software.amazon.awssdk:servicediscovery:2.17.191')
implementation("io.micronaut.aws:micronaut-aws-service-discovery:3.4.0")

Implementing DiscoveryClient interface

interface DiscoveryClient
extends Closeable, AutoCloseable, Described {
  fun getInstances(serviceId: String?): Publisher<List<ServiceInstance>?>
  fun getServiceIds(): Publisher<List<String?>?>
}

Custom AWS Discovery Implementation

This will allow us to fetch the IPs and Port of the service running in a given namespace. This IP and Port can be used to connect the respective service. AWS Service Discovery use Route 53 to fetch these details

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *