Spring Cloud 01

Source: Internet
Author: User

1 Spring Cloud provides distributed system tools

Configuration Center, service discovery, fuse (timeout error handling), routing (intercept), micro agent, Control bus, leader election, distributed session, cluster status

2 • Touched sub-item

Config, config Item + Config Center (local, Git, subversion)

Netflix, developer Kit, including Eureka, Hystrix, Zuul, Archaius, etc.

Hystrix, fault-tolerant management tools

Zuul, Edge Service tool, provides dynamic routing, monitoring, resiliency, security services

3 • Service Discovery Module

1 pom File

Spring-cloud-starter-eureka-server

2 · Add @enableeurekaserver annotations on the app class

3 · configuration file

server.port=1111

#禁用它的客户端注册行为

Eureka.client.register-with-eureka=false

Eureka.client.fetch-registry=false

#注册中心地址

eureka.client.serviceurl.defaultzone=http://localhost:${server.port}/eureka/

4 · Producers

1 Pom Dependency

Spring-cloud-starter-eureka

2 · Add @enablediscoveryclient annotations on the app class

3 • Configuration information

#服务实例名

Spring.application.name

server.port=2222

    eureka.client.serviceurl.defaultzone=http://localhost:1111/eureka/

5 · Consumer

1 • Load Balancing using the Ribbon

The Ribbon is an HTTP and TCP client-based load balancer that polls for access through the Ribbonserverlist server-side list configured in the client

When the ribbon and Eureka are federated, Ribbobserverlist is discoveryenabledniwsserverlist rewritten to get the server-side list from the Eureka registry. and use niwsdiscoveryping to get rid of iping.

2 Ribbon Use

Pom dependency: Spring-cloud-starter-ribbon

Annotation on App class @EnableDiscoveryClient to add Discovery service capabilities, @EnableFeignClients annotations request other services

Create Resttemplate instances in the app class and turn on load balancing via @[email protected] annotations

6 • Circuit breaker (processing delay, error failure)

Returns an error to the caller corresponding to a long wait

Use Hystrix in spring cloud

Use

1 Pom Dependency

Spring-cloud-starter-hystrix

2 · @enablecircuitbreaker on the app class to turn on the circuit breaker function

3 · Specify the callback method by adding annotations to the function that uses the Ribbon consumer service @HystrixCommand .

Feign using Hystrix

Pom does not need to be introduced into the hystrix,feign that has relied on

Specifying the callback class using the fallback property of the @feignclient annotation

Create callback classes implement this excuse to implement error handling methods

7 • Configuration Center

Principle

Store configuration files on git

Config-server Connecting to Git

Config-client Connecting to Config-server

When you start Config-client, Config-client gets the configuration file on the remote git via config-server and loads it into the object by soring

Use

1 • Add pom dependency

Spring-cloud-config-server

2 · App class on @enableconfigserver

3 · configuration file

Spring.application.name=config-server

server.port=7001

Spring.cloud.config.server.git.uri=http://git.oschina.net/zjb_china/springcloud-learning

Spring.cloud.config.server.git.searchpaths=chapter9-1-4/config-repo

Spring.cloud.config.server.git.password=password

4 • Warehouses generally have four types of files

      

      • Users.properties
      • Users-dev.properties
      • Users-test.properties
      • Users-prod.properties

5 ' URL and configuration file mapping relationship

      /{label}/{application}-{profile}.yml,{label} corresponds to different branches on git, default to Master

Example: To access the Dev2 branch, the Users app's prod environment can be accessed by: HTTP://LOCALHOST:7001/USERS/PROD/DEC2

6 ' How Consumers Get configuration information

1 ' pom dependent: Spring-cloud-starter-config

2 ' boostrap.yml configuration Config-server

        Spring.application.name=users

        Spring.cloud.config.profile=test

Spring.cloud.config.label=dev2

         Spring.cloud.config.discovery.serviceid=config-server

          Spring.cloud.config.discovery.enabled=true

server.port=7002

3 '@Value ("${from}")

   Private String from; binding configure the From property of the service center configuration
7 • Update configuration information without restarting Config-client
Adding pom dependencies to the client: Spring-boot-starter-actuator
@refreshscope adornments on Java classes that require automatic update configuration
When you update the configuration file on git later, the config client executes http://localhost:8080/refresh to update the refresh configuration variable into memory.
So the question comes, what about the cluster?
Use spring Cloud Bus to resolve
Need to rely on AMQP, Redis, Kafka components
















































Spring Cloud 01

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.