Spring Cloud: Replace config server with consul

Source: Internet
Author: User

Last mention, Eureka 2.x official Stop update, you can use Consul to replace, if the use of consul, in fact, config server does not need to continue to use, consul with KV storage, can completely replace the job of config server.

The steps are as follows:

First, add a jar dependency

    compile ' org.springframework.cloud:spring-cloud-starter-config '    compile ' org.springframework.cloud: Spring-cloud-starter-consul-config '

Before the dependency of config server is removed, it can be replaced by consul-config dependency.

Ii. Modification of BOOTSTRAP.YML file

1 Spring:2   ...3 Cloud:4 Consul:5host:127.0.0.16port:85007 Discovery:8Tags:version=1.0,author=Yjmyzz9Healthcheckpath:/Info.jsonTen healthcheckinterval:5s One instanceId: ${spring.application.name}:${spring.cloud.client.ipaddress} A enabled:true - Config: - enabled:true the Format:yaml - Prefix:config - defaultcontext:application -Profileseparator:',' +data-Key:data - #Config: + #Label:dev A #Discovery: at #enabled:true - #Service-id:my-config-server - #fail-fast:true - #Retry: - #max-interval:1500 - #Max-attempts:5 in #multiplier:1.2

The key is 13-19 lines, explain:

15 row Format:yaml represents the value content in the Key-value in Consul, in YAML format

16 row Prefix:config means the folder root directory Consul used to store the configuration is named Config

17 Line Defaultcontext:application represents the application name for the configuration file (eg: if your service is intended to be called MyApp, the application here will be replaced with MyApp)

18 Line Profileseparator: ', ' indicates if there is more than one profile (eg: Dev environment, testing environment test ...), the key name between the profile and Defaultcontext, with what delimiter to express (here is a bit confusing , which will be explained in detail later)

19 Row Data-key:data represents the key value name of the last layer node, which is typically the default data

Iii. Creating a KV configuration node in consul

Many articles, including official documents This step is unclear, the key is the name of the node naming rules , and bootstrap.yml in the same configuration, such as we want to create a test environment configuration, key name can be taken as:

Config/application,test/data

Here, each part of the BOOTSTRAP.YML in line with the previous step in the same, the 5 cut-off points, we combined with the previous step of 15-19 interpretation of the experience.

Then the value of the part, the configuration content in yml format to fill in the line:

Tips: Usually when developing, generally use Consul dev mode, the development mode KV storage will not persist storage, all in memory (restart Consul lost!) , so it is generally recommended to yml the contents of the configuration file, save a file in the project, start debugging, directly paste the configuration file contents into the Value box.

OK, now you can try to start under, smooth words, should be able to, is not very simple, the key also eliminates the deployment of Config server, help the company to save the machine, do not forget to let the leadership to you plus performance Oh ^_^

Reference Documentation:

1. Spring Cloud Consul Chinese document

2. Spring Cloud Consul Official document (US)

Spring Cloud: Replace config server with consul

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.