2022年6月20日 星期一

spring cloud

Spring Cloud Config

https://spring.io/projects/spring-cloud-config

Set up all instance Cloud Config into Git

Spring Cloud Config provides server and client-side support for externalized configuration in a distributed system. With the Config Server you have a central place to manage external properties for applications across all environments. 

=================================

# Install Git and Create Git Repository

#Connect Spring Cloud server to Local Git Repsoity 

==> Spring.clould .config.server.git.url = file://git path

@ EnableConfigServer


# Connect Limits Service to Spring Cloud Config

=> Choose Config Client dependency 

=> spring.config.import=optional:configserver:http://localhost:8888

===============================

there are multiple environments for the limits-services; a dev environment, production environment, 

# Configuring Profiles for Limit SErvice

============================



Features

Spring Cloud Config Server features:

  • HTTP, resource-based API for external configuration (name-value pairs, or equivalent YAML content)

  • Encrypt and decrypt property values (symmetric or asymmetric)

  • Embeddable easily in a Spring Boot application using @EnableConfigServer

Config Client features (for Spring applications):

  • Bind to the Config Server and initialize Spring Environment with remote property sources

  • Encrypt and decrypt property values (symmetric or asymmetric)


====================

# Setup up dynamic Port in the Response

=================

# Configure JPA and initailized data=

spring.jpa.show-sql=true

spring.datasource.url=jdbc

=====================

# Create JPA Repository 

=================

# Creating Feign Rest Client for Service invocation

https://spring.io/projects/spring-cloud-openfeign


#CurrencyExchangeProxy (interface)


@FeignClient(name="currency-exchange", url="locahost:8000")


https://spring.io/projects/spring-cloud-openfeign


https://spring.io/projects/spring-cloud-netflix


proxy.retrieveExchangeValue


  • Declarative REST Client: Feign creates a dynamic implementation of an interface decorated with JAX-RS or Spring MVC annotations


================

Eureka Naming Server (Spring Cloud Discovery)

https://spring.io/projects/spring-cloud-netflix


All the instances of all the micros services would register with a service registry

it would ask the service registry, what are the addresses of the currency exchange?




all the instance would register with the naming server or the service registry


@spring-cloud-starter-netflix-eureka-server


@EnableEurekaServer

https://spring.io/projects/spring-cloud-netflix


Features

Spring Cloud Netflix features:

  • Service Discovery: Eureka instances can be registered and clients can discover the instances using Spring-managed beans

  • Service Discovery: an embedded Eureka server can be created with declarative Java configuration

@EnableEurekaClient will try to contact a Eureka server on http://localhost:8761 (the default value of eureka.client.serviceUrl.defaultZone):


#spring-cloud-starter-netflix-eureka-client

#eureka.client.serviceurl.defaultzone=http://localhost:8761/eureka



=============

Spring Cloud Loadbalancer

#Load Balancing with Eureka, Feign, Spring cloud loadbalancer 

https://spring.io/blog/2020/03/25/spring-tips-spring-cloud-loadbalancer

https://spring.io/projects/spring-cloud-commons

Spring Cloud Load Balancer并不是一个独立的项目,而是spring-cloud-commons其中的一个模块。 项目中用了Eureka以及相关的 starter,想完全剔除Ribbon的相关依赖基本是不可能的,Spring 社区的人也是看到了这一点,通过配置去关闭Ribbon启用Spring-Cloud-LoadBalancer。


@FeignClient(name="currency-exchange"


eureka-client with spring-cloud-starter-loadbalancer (jar)

===================

Spring Cloud Gateway

Features

Spring Cloud Gateway features:


Built on Spring Framework 5, Project Reactor and Spring Boot 2.0


Able to match routes on any request attribute.


Predicates and filters are specific to routes.


Circuit Breaker integration.


Spring Cloud DiscoveryClient integration


Easy to write Predicates and Filters


Request Rate Limiting


Path Rewriting


https://spring.io/projects/spring-cloud-gateway


This project provides a library for building an API Gateway on top of Spring WebFlux. Spring Cloud Gateway aims to provide a simple, yet effective way to route to APIs and provide cross cutting concerns to them such as: security, monitoring/metrics, and resiliency.


# spring.cloud.gateway.discovery.locator.enabled=true

#Implement Spring CloudGateway Logging Filter

#LoggingFilter implements GlobalFilter

slf4j.logger

private Logger logger

@Override

public Mono<Void> filter (ServerWebExchange exchange, GatewayFilterChain chain)

logger.info("Path of the request receexchange.getRequest()

return chain.filter(exchange)


==========

Spring Cloud Circuit Breaker

https://spring.io/projects/spring-cloud-circuitbreaker


Introduction

Spring Cloud Circuit breaker provides an abstraction across different circuit breaker implementations. It provides a consistent API to use in your applications allowing you the developer to choose the circuit breaker implementation that best fits your needs for your app.


Supported Implementations

Resilience4J


Spring Retry


#Getting Started with Circuit Breaker - Resillence 4j

#Playing with Resillence4j - Retry and Fallback Method

# Playing with Circuit Breaker Features of Resillience4j


===================

Distribute tracing server (Zipkin) 

https://spring.io/projects/spring-cloud-sleuth


Spring Cloud Sleuth provides Spring Boot auto-configuration for distributed tracing.

Specifically, Spring Cloud Sleuth…​


Adds trace and span ids to the Slf4J MDC, so you can extract all the logs from a given trace or span in a log aggregator.


Instruments common ingress and egress points from Spring applications (servlet filter, rest template, scheduled actions, message channels, feign client).


If spring-cloud-sleuth-zipkin is available then the app will generate and report Zipkin-compatible traces via HTTP. By default it sends them to a Zipkin collector service on localhost (port 9411). Configure the location of the service using spring.zipkin.baseUrl.

https://spring.io/guides

=======================



https://spring.io/projects/spring-cloud-zookeeper

https://spring.io/projects/spring-cloud-security

https://spring.io/projects/spring-cloud-pipelines

https://spring.io/projects/spring-cloud-commons

https://spring.io/projects/spring-cloud-aws

https://spring.io/projects/spring-cloud-connectors

https://spring.io/projects/spring-cloud-kubernetes


https://spring.io/projects/spring-cloud-bus



https://spring.io/projects/spring-cloud




=====

Dependency

@spring-boot -starter -acctuator

@spring-boot-starter-web

@spring-boot-starter-data-jpa

@spring-boot-cloud-starter-config

@com.h2database

@spring-cloud-openfeign


沒有留言:

張貼留言

IT Knowledge Map

https://docs.google.com/spreadsheets/d/1ZmN7G1unUAEpTPp5ObDnlAUtILLwwvluy-KHumMPEUU/edit#gid=0