[Spring Cloud] Spring Cloud Study Notes 1

1Download
JDK 1.8

2Download
JCE 1.8
Unzip it to: JDK/jre/lib/security

3Download
Eclipse

4Download
Maven

5
property source: property profile
enviroment: spring.profiles.active
    - bootstrap context: bootstrap.properties/bootstrap.yml ( Default configuration, load first)
        - application context: application.yml.properties/application.yml


6
Remote configuration warehouse: configuration center
GIT
# Configure server address (default port: 8080)
spring.cloud.config.uri=

# Force pull the latest Version data
spring.cloud.config.force-pull=true

spring.config.name=configserver
server.port=8080

# Client connection default port: 8888
spring.cloud.config.failFast=true



# Enable local configuration to override configuration center configuration (configuration center)
spring.cloud.config.allowOverride=true
# Disable local configuration to override configuration center configuration (configuration center)
spring.cloud.config.overrideNone=true
# Enable local configuration to override configuration center configuration , but does not override the local configuration
spring.cloud.config.overrideSystemProperties=false

# Support cross-environment management configuration files (DEV/SIT/UAT/PRODUCION)
# The configuration file is obtained from the GIT repository
spring.cloud.config.server.git.uri= https://github.com/spring-cloud-samples/config-repo

# Authentication (spring-boot-starter-security)
spring.cloud.config.server.git.username=
spring.cloud.config.server.git. password=

spring:
  datasource:
    username: dbuser
    password: '{cipher}FKSAJDFGYOS8F7GLHAKERGFHLSAJ'

# Generate certificate
keytool -genkeypair -alias mytestkey -keyalg RSA \
  -dname "CN=Web Server,OU=Unit,O=Organization,L=City,S=State,C=US" \
  -keypass changeme -keystore server.jks -storepass letmein

# Configure certificate (bootstrap.yml)
encrypt:
  keyStore:
    location: classpath:/server.jks
    password: letmein
    alias: mytestkey
    secret: changeme

# Disable temporary directory
spring.cloud.config.server.git.basedir

# Configuration file naming convention
/ {application}/{profile}[/{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label }/{application}-{profile}.properties

application: spring.application.name
profile: spring.prifiles.active
label: master/git branch label name

# git add config file
$ cd $HOME
$ mkdir config-repo
$ cd config-repo
$ git init .
$ echo info.foo : bar > application.properties
$ git add -A .
$ git commit -m "Add application.properties"



7
service discovery
Eureka/Consul/Zoookeeper

server:
  port: 8761

eureka:
  instance:
    hostname: localhost
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

eureka.instance.preferIpAddress=true
eureka.instance.leaseRenewalIntervalInSeconds

client registration
via META-INF/spring.factories org. springframework.cloud.client.discovery.EnableDiscoveryClient=

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/

# Disable automatic registration
@EnableDiscoveryClient(autoRegister=false)
# Disable automatic registration
spring.cloud.service-registry .auto-registration.enabled=false

eureka:
  instance:
    ...
    metadataMap:
      user: osufhalskjrtl
      password: lviuhlszvaorhvlo5847
      configPath: /config

8
load balancing
ribbon/zuul

zuul:
  threadPool:
    useSeparateThreadPools: true
    threadPoolKeyPrefix: zuulgw
stores:
  ribbon:
    listOfServers: example.com,google.com

# Disable failure retry (Spring Retry)
spring.cloud.loadbalancer.retry. enabled=false
client.ribbon.MaxAutoRetries=3 client.ribbon.MaxAutoRetriesNextServer
=
client.ribbon.OkToRetryOnAllOperations #

Coexistence of different load balancing strategies
spring.aop.proxyTargetClass=true

# Specify network interface
spring:
  cloud:
    inetutils:
      preferredNetworks:
        - 192.168
        - 10.0

# 排除网络接口
spring:
  cloud:
    inetutils:
      ignoredInterfaces:
        - docker0
        - veth.*
# 指定站点本地接口
spring:
  cloud:
    inetutils:
      useOnlySiteLocalInterfaces: true

9
HTTP Client/OK Http Client

spring.cloud.httpclientfactories.apache.enabled=true
spring.cloud.httpclientfactories.ok.enabled=false

10
熔断
Hystrix/Turbine
circuitBreaker.requestVolumeThreshold=20
circuitBreaker.errorThresholdPercentage=>50%
metrics.rollingStats.timeInMilliseconds=10

@HystrixCommand

11
REST
Feign
@FeignClient

feign:
  client:
    config:
      feignName:
        connectTimeout: 5000
        readTimeout: 5000
        loggerLevel: full
        errorDecoder: com.example.SimpleErrorDecoder
        retryer: com.example.SimpleRetryer
        requestInterceptors:
          - com.example.FooRequestInterceptor
          - com.example.BarRequestInterceptor
        decode404: false

feign:
  hystrix:
    enabled: false


hystrix:
  command:
    default:
      execution:
        isolation:
          strategy: SEMAPHORE #

Import configuration
@Import

# Injection
@Autowired

# Configuration
@Configuration
@Bean
@Scope

# Request compression
feign.compression.request.enabled=true
feign.compression.response.enabled= true


12Logging.level.cn.bisoft : DEBUG 13 server-side routing zuul zuul:   routes:     users:       path: /myusers/**       serviceId: users_service uul:   routes:     echo:       path: /myusers/**       serviceId: myusers-service       stripPrefix: true hystrix:





















  command:
    myusers-service:
      execution:
        isolation:
          thread:
            timeoutInMilliseconds: ...

myusers-service:
  ribbon:
    NIWSServerListClassName: com.netflix.loadbalancer.ConfigurationBasedServerList
    ListOfServers: http://example1.com,http://example2.com
    ConnectTimeout: 1000
    ReadTimeout: 3000
    MaxTotalHttpConnections: 500
    MaxConnectionsPerHost: 100

# 客户端
zuul:
  routes:
    users:
      path: /myusers/**
      sensitiveHeaders: Cookie,Set-Cookie,Authorization
      url: https://downstream

endpoints.routes.enabled=false

hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 60000
ribbon:
  ConnectTimeout: 3000
  ReadTimeout: 60000

zuul:
  forceOriginalQueryStringEncoding: true

zuul.servlet-path


zuul.host.connect-timeout-millis=
zuul.host.socket-timeout-millis=

14
RxJAVA

异步基于事件

15
Stream/Kafka/RabbitMQ

16
BUS

17
SSO
OAuth2




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326112704&siteId=291194637