Brief introduction
When our business systems become more and more complex, various configurations can be layered out of the pack. Once the configuration has been modified, then we have to modify the after-stop service, and then go online, if the service is small, we can manually operate, if it is hundreds of services, if it is manual operation, it is certainly inappropriate, and then springcloudconfig out, Is our usual sense of the configuration center, the application originally placed in the local file configuration extracted from the central server, so as to provide better management, publishing capabilities.
Springcloudconfig sub-server and client, the server is responsible for the GIT (SVN or local file system) stored in the configuration file as a rest interface, the client can get the configuration from the server side rest interface. However, the client is not actively aware of the changes to the configuration, thereby proactively acquiring a new configuration, which requires each client to trigger its own through the Post method /refresh
.
Springcloudbus connects the nodes of a distributed system through a lightweight message broker. This can be used for broadcast state changes (such as configuration changes) or other management directives. Springcloudbus provides a endpoint that is accessed via the Post method, which is /bus/refresh
typically called by the Webhook function of Git to notify the client of each springcloudconfig to update the configuration on the server. This section will tell you how to build a set of Spring Cloud Config automatically refreshed
First, create the module
The modules are structured as follows:
Second, Maven aggregation module Microservice-config pom.xml file
<?xml version= "1.0" encoding= "UTF-8"? ><project xmlns= "http://maven.apache.org/POM/4.0.0"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > <parent> <groupid& Gt;org.springframework.boot</groupid> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.5.RELEASE</version> </parent> <modelVersion>4.0.0</modelVersion> <g Roupid>com.jacky</groupid> <artifactId>miroservice-config</artifactId> <packaging>pom </packaging> <version>1.0-SNAPSHOT</version> <modules> <module>microservice-con Fig-server</module> <module>microservice-config-eureka</module> <module>microservice -config-client</module> </modules> <properties> <project.build.sourceencoding>utf-8& Lt;/project.build.sourceencoding> <project.reporting.outputencoding>utf-8</ Project.reporting.outputencoding> <java.version>1.8</java.version> <docker.image.prefix>jacky</docker.image.prefix><!--Configuring the properties of a mirrored warehouse-- > <docker.repostory>192.168.6.132:5000</docker.repostory><!--Configure the corresponding address and port of the mirrored warehouse--</proper ties> <dependencyManagement> <dependencies> <dependency> <gro Upid>org.springframework.cloud</groupid> <artifactid>spring-cloud-dependencies</artifacti D> <version>Camden.SR7</version> <type>pom</type> <scope>Import</scope> </dependency> </dependencies> </dependencyManagement> <build& Gt <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> <!--add plug-ins to build Docker images with Maven plugins--<pluginManagement> <plugins> < Plugin> <groupId>com.spotify</groupId> <artifactid>docker-maven -plugin</artifactid> <version>0.4.13</version> </plugin> </plugins> </pluginManagement> </build> </project>
Third, Configuration Center module (MICROSERVICE-CONFIG-EUREKA)
3.1, Pom.xml
<?xml version= "1.0" encoding= "UTF-8"? ><project xmlns= "http://maven.apache.org/POM/4.0.0"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > <parent> <artifact Id>miroservice-config</artifactid> <groupId>com.jacky</groupId> <version>1.0-snap shot</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactid>microservi ce-config-eureka</artifactid> <packaging>jar</packaging> <properties> <project.bui ld.sourceencoding>utf-8</project.build.sourceencoding> </properties> <dependencies> < ;d ependency> <groupId>org.springframework.cloud</groupId> <ARTIFACTID>SPRING-CL oud-starter-eureka-server</artifactid> </dependency> <dependency> <GROUPID&G T;org.springframework.boot</groupid> <artifactId>spring-boot-starter-security</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupid> ;com.spotify</groupid> <artifactId>docker-maven-plugin</artifactId> <ex Ecutions> <!--setting up mirroring when executing maven install-<execution> <id>build-image</id> <phase>install</phase> <goals> <goal>build</goal> </goals> </execution> </executions> <configuration> <! --Installed Docker host, and opened API remote interface settings--<dockerhost>http://192.168.6.130:5678</dockerhost><pushImage>true</pushImage><!--Setting up an upload image to a private warehouse requires Docker settings specify the private warehouse address--<!--mirror name--< Imagename>${docker.repostory}/${docker.image.prefix}/${project.artifactid}:${project.version}</imagename > <!--the base version of the image--<BASEIMAGE>JAVA:OPENJDK-8-JDK-ALPINE</BASEIMAGE&G T <!--mirroring boot Parameters--<entrypoint>["Java", "-jar", "/${project.build.finalname}.jar"]</entrypoin t> <resources> <resource> <TARGETPA Th>/</targetpath> <directory>${project.build.directory}</directory> <include>${project.build.finalName}.jar</include> </resource> ; </resources> </configuration> </plugin> </plugins> </build></project>
3.2, Application.yml
Spring: application: name:microservice-config-serversecurity: basic: True User: name:jacky password:adminserver: 9511Eureka: client: Register false fetchfalse service-URL: defaultzone:http:// jacky:[email Protected]:9511/eureka
3.3. Startup class Eurekaapplication.java
PackageCom.jacky.cloud;Importorg.springframework.boot.SpringApplication;Importorg.springframework.boot.autoconfigure.SpringBootApplication;ImportOrg.springframework.cloud.netflix.eureka.server.EnableEurekaServer, @ Springbootapplication@enableeurekaserver Public classeurekaapplication { Public Static voidMain (string[] args) {Springapplication.run (eurekaapplication.class, args); } }
3.3. Startup class Eurekaapplication.java
PackageCom.jacky.cloud;Importorg.springframework.boot.SpringApplication;Importorg.springframework.boot.autoconfigure.SpringBootApplication;ImportOrg.springframework.cloud.netflix.eureka.server.EnableEurekaServer, @ Springbootapplication@enableeurekaserver Public classeurekaapplication { Public Static voidMain (string[] args) {Springapplication.run (eurekaapplication.class, args); } }
Iv. Configuration Center Server (microservice-config-server)
4.1. pom.xml File
<?xml version= "1.0" encoding= "UTF-8"? ><project xmlns= "http://maven.apache.org/POM/4.0.0"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > <parent> <artifact Id>miroservice-config</artifactid> <groupId>com.jacky</groupId> <version>1.0-snap shot</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactid>microservi ce-config-server</artifactid> <packaging>jar</packaging> <properties> <project.bu ild.sourceencoding>utf-8</project.build.sourceencoding> </properties> <dependencies> &L T;dependency> <groupId>org.springframework.cloud</groupId> <artifactid>spring-c loud-config-server</artifactid> </dependency> <dependency> <groupid>org.s Pringframework.cloud</groupid> <artifactId>spring-cloud-starter-eureka</artifactId> &L T;/dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactid>sprin G-cloud-starter-bus-amqp</artifactid> </dependency> <!--Configure the required package--<dependency > <groupId>org.springframework.boot</groupId> <artifactid>spring-boot-starter-s ecurity</artifactid> </dependency> <dependency> <groupid>org.springframew Ork.boot</groupid> <artifactId>spring-boot-starter-actuator</artifactId> </dependen cy> </dependencies> <build> <plugins> <plugin> <grou Pid>com.spotify</groupid> <artifactId>docker-maven-plugin</artifactId> <executions> <!--setting up mirroring when executing maven install--<execution> <id>Build-image</id> <phase>install</phase> <goals> <goal>build</goal> </goals> </execut Ion> </executions> <configuration> <!--hosts with Docker installed and Open the API remote interface setting--<dockerhost>http://192.168.6.130:5678</dockerhost><pushImage>true</pushImage><!--Setting up an upload image to a private warehouse requires Docker settings specify the private warehouse address--<!--mirror name--< Imagename>${docker.repostory}/${docker.image.prefix}/${project.artifactid}:${project.version}</imagename > <!--the base version of the image--<BASEIMAGE>JAVA:OPENJDK-8-JDK-ALPINE</BASEIMAGE&G T <!--mirroring boot Parameters--<entrypoint>["Java", "-jar", "/${project.build.finalname}.jar"]</entrypoin t> <resources> <resource> <TARGETPA Th>/</targetpath> <directory>${project.build.directory}</directory> <include>${project.build.finalName}.jar</include> </resource> ; </resources> </configuration> </plugin> </plugins> </build> </project>
4.2. application.yml File
Server:port:9518Eureka:instance:prefer-ip-address:true# Open Health Check (requires spring-boot-starter-Actuator dependent) lease-expiration-duration-in-seconds:90#续约到期时间 (unit S) By default is 90S lease-renewal-interval-in-seconds:30# Renewal Interval (default 30 seconds) instance-ID: ${spring.application.name}:${spring.cloud.client.ipaddress}:${spring.application.instance_id:${ Server.port}} client:serviceUrl:defaultZone:http://Jacky:[email protected]:9511/eureka/#把configservice注册到eureka上 so that the client can find configservice through the information registered on the Eureka#实现的基本的 httpbasic certification security:basic:enabled:true# Turn on HTTP basic-based Authentication user:name:jacky123 # Configure Login's account password:admin123 # Configure password for login #spring:applicatio N:name:microservice-config-Service cloud:config:server:git:uri:http://Git.oschina.net/jacky-lulu/microservice-config-repo #配置git仓库位置Clone-on-start:true#在启动的时候克隆仓库 Search-paths: ' {application} '#配置仓库路径下的相对搜索位置, you can configure multiple Username:myuser #填写git仓库的用户名 password:mypass #填写git仓库的密码 RABBITMQ: Host:192.168.6.130Port:5672Username:myuser Password:mypass
Source source technical support for complete projects 2147775633
Springcloud-config-bus (13)