How to use distributed configuration center

This is the back-end small class of the monastery. Each article is shared from

[background introduction] [knowledge analysis] [common problems] [solutions] [coding practice] [extended thinking] [more discussion] [References]

Eight aspects of in-depth analysis of back-end knowledge / skills. This article shares:

[how to use distributed configuration center]

Hello, I am the 11th student of Shenzhen Branch of it Academy. I am an honest, pure and kind java programmer.

Today, I'd like to share with you a knowledge point of Java task 10 on the official website of the Academy: how to use the distributed configuration center?

1 background introduction

1.1 introduction to spring cloud

Springcloud is a complete set of framework for implementing microservices based on springboot. It provides configuration management, service discovery, circuit breaker, intelligent routing, micro agent, control bus, global lock, decision election, distributed session and cluster state management required for microservice development.

Springboot aims to simplify the creation of product level spring applications and services, simplify configuration files, use embedded web servers, and contain many out of the box microservice functions

2 knowledge analysis

2.1 what is a distributed configuration center?

In the system of microservice architecture, a unified microservice is used to load the configuration file, and the microservice provides the configuration file to other services. This microservice is the configuration center.

2.2 what is spring cloudbus?

Spring cloud bus is the message bus of spring cloud framework. Its essence is to use the broadcast mechanism of MQ to spread messages in distributed systems. At present, Kafka and rabbitmq are commonly used. There are many things that can be done by using the bus mechanism, and the client refresh of the configuration center is one of the typical application scenarios.

2.3 what are the steps to automatically update the configuration using spring cloudbus?

1) Set the configuration center, config server, and obtain configuration information from git;

2) call the relevant configuration in config-server in service;

3) Import spring cloudbus related dependencies in the service and configure rabbitmq;

4) Add the @ refreshscope annotation on the controller that needs to refresh the configuration

5) Configure webhook on GitHub, set and update the properties file, and send a post request to config server.

3 frequently asked questions

How to use spring cloudbus to implement automatic configuration update

4 Solutions

1. See coding practice

5 coding practice

YML configuration of config server

server:

port: 8091

eureka:

instance:

prefer-ip-address: true

client:

registerWithEureka: true

fetchRegistry: true

serviceUrl:

defaultZone: http://localhost:8090/eureka/

spring:

application:

name: config-server

cloud:

config:

server:

git:

uri: https://github.com/

search-paths: respo

label: master

bus:

enabled: true

trace:

enabled: true

rabbitmq:

host: localhost

port: 5672

username: guest

password: guest

management:

endpoints:

web:

exposure:

include: bus-refresh

YML configuration of service

server:

port: 8081

spring:

application:

name: service-hi

cloud:

bus:

enabled: true

trace:

enabled: true

config:

lable: master

profile: dev

uri: http://193.112.45.68:8091/

rabbitmq:

host: 193.112. forty-five point six eight

port: 5672

username: guest

password: guest

eureka:

client:

registerWithEureka: true

fetchRegistry: true

serviceUrl:

defaultZone: http://193.112.45.68:8090/eureka/

instance:

hostname: localhost

import org. springframework. beans. factory. annotation. Value;

import org. springframework. web. bind. annotation. RequestMapping;

import org. springframework. web. bind. annotation. RestController;

@RestController

public class Hello {

@Value("${type}")

private String type;

@RequestMapping(value = "/hello")

public String te() {

return type ;

}

}

import org. springframework. beans. factory. annotation. Value;

import org. springframework. cloud. context. config. annotation. RefreshScope;

import org. springframework. web. bind. annotation. RequestMapping;

import org. springframework. web. bind. annotation. RestController;

@RestController

@RefreshScope

public class Hi {

@Value("${type}")

private String type;

@RequestMapping(value = "/hi")

public String te() {

return type ;

}

}

6 extended thinking

7 references

CSDN, Baidu Encyclopedia

8 more discussion

8.1 what is the role of @ refreshscope?

This annotation is used to mark the class that needs to be refreshed. Only when this annotation is added can the configuration referenced by this class be refreshed.

8.2 do the service registration center, service configuration center and specific service modules have to be placed on the same server?

No, just specify and open the relevant ports in the YML file.

8.3 how to configure the webhook function of GitHub?

1) Find the connected library and open the setting page;

2) Select webhook and add a new webhook;

3) Fill in the address to send the post request and when to send the post request

Skill tree It Academy

"We believe that everyone can become an engineer. From now on, find a senior brother to introduce you, control your learning rhythm, and stop being confused on the way to learning.".

Here is the skill tree In it academy, thousands of senior brothers have found their own learning route here. Learning is transparent and growth is visible. Senior brothers have 1-to-1 free guidance.

Come and study with me~ http://www.jnshu.com/login/1/24864700

Tencent Video: https://v.qq.com/x/page/c0719197opo.html

Ppt link video link

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>