Giter Club home page Giter Club logo

lab-microservice-spring-aws's Introduction

Inter-Microservice Communication with OpenFeign using AWS AppMesh

Microservice is a service-oriented architecture where an application is deployed as a collection of loosely-coupled services. The goal is to make each service independent, fine-grained, scalable and flexible which allows faster testing and release.

This project takes advantage of the AWS infrastructure and it's services such as:

  • ECR - docker registry
  • ECS - service orchestration for service deployment, management, scaling, monitoring, etc
  • AppMesh - service mesh that provides application level networking (normally used between internal services)
  • Load Balancer - use for external client connection

Microservice Architecture with Spring on AWS

Our Microservices

Business Services

applicant-services - Dummy service that returns a list of applicant names.

@GetMapping("/profiles")
public List<String> getApplicantsByJob() {
 
    log.debug("port={} get applicants by job", port);
    return Arrays.asList("Steve", "Bill", "Linus");
}

job-services - Dummy service that returns a job title with a list of applicant names.

@GetMapping("/profiles")
public ResponseEntity listJobsWithApplicantProfiles() {
 
    log.debug("get job details with applicants");
 
    JobWithApplicantsDto result = new JobWithApplicantsDto();
    result.setJob("Java Developer");
 
    result.setApplicants(applicantProxy.getApplicantsByJob());
 
    return ResponseEntity.ok().body(result);
}

Spring Cloud Libraries

  • spring-cloud-starter-openfeign - this library is used for referencing a service in the naming server

To enable this feature, @EnableFeignClients must be annotated to a configuration class.

To call an endpoint from another service, an interface must be created with the same method signature as the method from the other service. In this example, we are importing 2 endpoints from the applicant-service.

@FeignClient(name = "applicant-services")
public interface ApplicantProxy {
 
    @GetMapping("/applicants/profiles")
    List<String> getApplicantsByJob();
 
    @GetMapping("/applicants/top")
    public List<String> getTopApplicantsByJob();
}
  • spring-cloud-starter-sleuth - this library helps us trace our requests across different microservices by automatically adding a unique id to the logs.

As we can see in the logs, it started from api-gateway, pass thru job-services, and then application-services. In the 3 logs, notice the common unique id: 3b4039e47fb602a9. We can use this when tracing a request.

Log trace

image

AWS Deployment

ECR

  • applicant-services
  • job-services

Cloud Map

  • czetsuyatech.lab (API, VPC)

Virtual Nodes

  • dev-vn-applicant-services
  • dev-vn-job-services

Virtual Services

  • dev-vs-applicant-services
  • dev-vs-job-services

ECS

Cluster - dev-layer3-businessservices

Services

  • Service - dev-service-applicant-services
  • Task Definition - dev-td-applicant-services

Containers

  • aws-xray-daemon amazon/aws-xray-daemon:1
  • envoy

Environment Variables

  • ENVOY_LOG_LEVEL=trace
  • ENABLE_ENVOY_XRAY_TRACING=1
  • XRAY_DAEMON_PORT=2000

Parameter Store

APPLICATION_SERVICE_URL=/dev/applicant-services/APPLICATION_SERVICE_URL=http://applicant-services.czetsuyatech.lab:8081

  • Service - dev-service-job-services
  • Task Definition - dev-td-job-services

Containers

  • aws-xray-daemon amazon/aws-xray-daemon:1
  • envoy

Environment Variables

  • ENVOY_LOG_LEVEL=trace
  • ENABLE_ENVOY_XRAY_TRACING=1
  • XRAY_DAEMON_PORT=2000

Services URLs

Applicant Services

Job Services

lab-microservice-spring-aws's People

Contributors

czetsuya avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.