Spring Cloud (eight): Configuration Center (service and high Availability) "version Finchley"

Source: Internet
Author: User

Spring Cloud (eight): Configuration Center (service and high Availability) "version Finchley" Posted in 2018-04-19 | updated on 2018-04-26 |

In this article, "Spring Cloud (vii): Configuration Center (Git, Refresh)" continues to say the use of Spring cloud Config.

Let's review what we've accomplished in the previous article:

    • Built the config-server to connect to the Git repository
    • A Config-repo directory was created on Git to store configuration information
    • Built the config-client to get configuration information in Git
    • Refresh is enabled in Config-client, dynamically refreshes configuration information

In this article, we continue to look at some of the other capabilities of Spring Cloud Config.

Traditional approaches to high-availability issues

Normally in a production environment, Config Server, like the service registry, we also need to extend it to a highly available cluster. It is very simple to achieve high availability on a previously implemented config-server basis, and we do not need to do any additional configuration for these servers, just follow one configuration rule: to point all config servers to the same Git repository, This allows all configuration content to be maintained through a unified shared file system, while the client specifies the config server location, as long as the balanced load outside of config server is configured, as shown in the structure:

Register as a service

Although server-side load balancing is already possible, the configuration management in the architecture itself can be seen as a micro-service in the architecture itself. So, another way to make it easier is to register config-server as a service so that all clients can access it in a service way. In this way, it is only necessary to launch multiple config-server that point to the same Git repository location to achieve high availability.

The configuration process is also very simple, and we are transforming it based on the content of the configuration center Git version.

Code Transformation Service Side Retrofit Add dependency

Add the following dependencies inside the Pom.xml

Copy
1
2
3
4
<dependency>
<groupid>org.springframework.cloud</groupid>
<artifactid>spring-cloud-starter-netflix-eureka-client</artifactid>
</dependency>

Configuration file

Added Eureka configuration in application.yml

Copy
1
2
3
4
Eureka
Client
Service-url:
http://localhost:7000/eureka/

This completes the Server-side transformation. Start the Eureka registry first, on the server side, and in the browser: Http://localhost:7000/will see that the server side is registered to the registry.

Client Retrofit Add DependencyCopy
1
2
3
4
<dependency>
<groupid>org.springframework.cloud</groupid>
<artifactid>spring-cloud-starter-netflix-eureka-client</artifactid>
</dependency>
Configuration file

Bootstrap.yml

Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
Spring
cloud:
Name: config-client
label: master
discovery:
enabled: true
config-server
eureka:
client:
Service-url:
Defaultzone: http://localhost:7000/ eureka/

The main point is spring.cloud.config.uri to remove the configuration directly pointing to the server-side address, adding the last three configurations:

    • spring.cloud.config.discovery.enabled: Open Config Service discovery support
    • spring.cloud.config.discovery.serviceId: Specifies the server-side name, which is the server-side spring.application.name value
    • eureka.client.service-url.defaultZone: Address to Configuration Center

All three configuration files need to be placed bootstrap.yml in the configuration.

Start client side, access in browser: Http://localhost:7000/will see that both the Server side and client side are registered to the registry.

Highly Available

To simulate the production cluster environment, we launched two server-side ports of 12000 and 12001, respectively, providing highly available server-side support.

Copy
1
2
3
4
5
6
Packaged
./MVNW Clean Package-dmaven.test.skip=true

Start two servers
Java-jar Target/spring-cloud-config-server-0.0.1-snapshot.jar--server.port=12000
Java-jar Target/spring-cloud-config-server-0.0.1-snapshot.jar--server.port=12001

It can be found that there will be two servers at the same time to provide configuration center services, to prevent one down after the impact of the entire system to use.

We first test the server side separately, Access: Http://localhost:12000/config-client/dev and Http://localhost:12001/config-client/dev return information:

Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
"Name":"Config-client",
"Profiles": [
"Dev"
],
"label": NULL,
"version": "90dd76966da0eed967a0cbce3320f0f7ff63eb6b",
"state": null,
"Propertysources": [
{
"name": "Https://github.com/zhaoyibo/spring-cloud-study/config-repo/config-client-dev.yml",
"source": {
"Info.profile": "Dev Update"
}
}
]
}

Note The configuration information is read correctly on both Server sides.

Visit Http://localhost:13000/info again to return dev update . Stating that the client has read the contents of the server side, we randomly stop a server-side service, re-visit Http://localhost:13000/info still returns dev update , stating that the purpose of achieving high availability.

Related reading

Spring Cloud (i): Overview of service governance Technologies
Spring Cloud (ii): Service Registration and Discovery Eureka
Spring Cloud (iii): service delivery and invocation Eureka
Spring Cloud (iv): Service-tolerant protection hystrix
Spring Cloud (v): Hystrix Monitor Panel
Spring Cloud (vi): Hystrix monitoring Data Aggregation Turbine
Spring Cloud (vii): Configuration Center (Git vs. dynamic refresh)
Spring Cloud (eight): Configuration Center (service and high availability)
Spring Cloud (ix): Configuration Center (message bus)
Spring Cloud (10): Service Gateway Zuul (routing)
Spring Cloud (11): Service Gateway Zuul (filter)
Spring Cloud (12): Distributed Link Tracking (Sleuth and Zipkin)

Sample code: GitHub

Reference

Springcloud (eight): Configure hub service and high availability
Spring Cloud Building MicroServices Architecture (iv) Distributed Configuration Center (cont.)

    • this article Yibo
    • This article link: https://windmt.com/2018/04/19/spring-cloud-8-config-with-eureka/
    • Copyright Notice: All articles in this blog are subject to the CC BY-NC-SA 4.0 license Agreement except for special statements. Reprint please specify the source!

Spring Cloud (eight): Configuration Center (service and high Availability) "version Finchley"

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.