Skip to content

rexrk/Java_Microservices

Repository files navigation

Progress Track

Microservices

Day 1

Config Client | Config Client | Config Client
           \1        |2         /3
               +-------------+
               |Config Server|
               +-------------+

Day 2

  • Fetching values from application properties to a class variables.

    @ConfigurationProperties("{name}")

  • Centralized Configuration of Microservice server

    Dependency : Spring-Cloud-Config-Server

  • Adding git to config server application.

    • higher priority

Day 3

  • Server Configurations :

    spring.cloud.config.server.git.uri=file:///{Current directory Path}
    port : server.port={port}

  • Clients Configurations :

    Dependency : spring-cloud-starter-config
    props : spring.config.import=optional:configserver:http://localhost:8888

  • Multiple Profiles in app.props (activate a profile):

    spring.profiles.active={name}
    spring.cloud.config.profile={name}

Day 4

Day 5

  • Eureka Naming server (Registry for microservices name):

    Dependency : spring-cloud-starter-netflix-eureka-client
    Main class : @EnableEurekaServer

    • Disable self discovery of server

      eureka.client.register-with-eureka=false
      eureka.client.fetch-registry=false

    • link : http://localhost:8761
  • Eureka Clients (service discovery) :

    eureka.client.service-url.defaultZone=http://localhost:8761/eureka

Day 6

  1. Define a @Configuration Class
  2. Define a @Bean of return type RouteLocator with parameters (RouteLocatorBuilder builder)
  3. Define routes :
  return builder.routes()
                .route(p -> p
                        .path("/get")
                //GatewayFilterSpec filters
                        .filters(f -> f
                                .addRequestHeader("{MyHeader}", "{MyURI}")
                                .addRequestParameter("{MyParam}", "{MyValue}"))
                        .uri("http://httpbin.org/get"))
                //predicate
                .route(p -> p
                        .path("/{path}/**")
                        .uri("lb://{path}"))
                //for rewriting paths
                .route(p -> p
                        .path("/currency-conversion-new/**")
                        .filters(f -> f.rewritePath("currency-conversion-new/(?<segment>.*)", "/currency-conversion-feign/${segment}"))
                        .uri("lb://currency-conversion"))
                .build(); 

Day 7

  • Spring Cloud Gateway Logging Filter

    class : implements gateway.filter.GlobalFilter implement method : Mono filter(ServerWebExchange exchange, GatewayFilterChain chain)

  • Circuit Breaker from Resilience4j

    Dependency : resilience4j-spring-boot2
    Dependency : spring-boot-starter-aop

    • @Retry(name = "{name}") on api method
      • fallback : @Retry(fallbackMethod={implemented Method name with accepting Exception param})
    • some properties :

      resilience4j.retry.instances.{api-name}.max-attempts=5
      resilience4j.retry.instances.{api-name}.wait-duration=2s
      resilience4j.retry.instances.{api-name}.enable-exponential-backoff=true

  • Breaking Circuit for failing microservices (closed -> open <-> half_open -> closed):

    @CircuitBreaker(name = "default", fallbackMethod = "fallbackRestTemplate")
    props : resilience4j.circuitbreaker.instances.{name}.{property}={value}

  • Rate Limiting

    @RateLimiter(name = {name})
    props : resilience4j.ratelimiter.instances.{name}.{property}={value}

  • Allowing Concurrent requeusts

    @BulkHead(name={name})

Microservices with Docker

Day 8

  • Docker commands

    Tailing logs : logs {id} -f
    Search Image : search {imageName}
    Stopping container : pause / unpause, stop, kill
    AutoRestart Container : run --restart=always
    Events : events
    Running process : top
    container details : stats
    cpu quota : run --cpu-quota={1-100000}
    memory : run -m {memSize}{m/g}
    docker daemon : system df

  • Distributed Tracing

    Tracing / Debugging

    • Run zipkin on port 9411
  • OpenTelemetry

    • Dependencies :

      Micrometer : micrometer-observation
      OpenTelemetry : micrometer-tracing-bridge-otel
      Zipkin : opentelemetry-exporter-zipkin

    • Properties :

      management.tracing.sampling.probability={,1.0}
      logging.pattern.level=%5p [${spring.application.name:},%X{traceId:-},%X{spanId:-}]

    • zipkin link : http://localhost:9411

    • Enable Tracing in feign api calls :

      Dependency : feign-micrometer

    • Integrate micrometer with RestTemplate :

      @Configuration(proxyBeanMethods = false)
      class RestTemplateConfiguration {
        //create RestTemplate using RestTemplateBuilder
        @Bean
        RestTemplate restTemplate(RestTemplateBuilder builder) {
            return builder.build();
        }
      }

Day 9

  • Creating container image from pom.xml
        <configuration>
            <image>
                <name>{imageName}</name>
            </image>
            <pullPolicy>IF_NOT_PRESENT</pullPolicy>
            //fixes {:} issue
            <docker>
                <host>//./pipe/dockerDesktopLinuxEngine</host>
            </docker>
        </configuration>
  - run image: docker run -p 8000:8000 devraman/ms-currency-exchange-service:0.0.1-SNAPSHOT

## Day 10

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages