This article focuses on the Spring Cloud Consul component, a tool that provides service discovery and configuration. Consul is distributed, highly available, and highly scalable.

Consul introduction

Consul has the following properties:

  • Service discovery: Consul registers a service over HTTP and the service interacts with the service.
  • Service health monitoring
  • The key/value store
  • Multi-data center

Consul runs on machines such as MAC, Windows and Linux.

Consul Installation

linux

$ mkdir -p $GOPATH/src/github.com/hashicorp && cd $!
$ git clone https://github.com/hashicorp/consul.git
$ cd consul
$ make bootstrap
$ make bootstrapCopy the code

3. Construction project

}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}

<? 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"> < modelVersion > 4.0.0 < / modelVersion > < groupId > com. Forezp < / groupId > < artifactId > consul - miya < / artifactId > <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name> Consul-miya </name> <description>Demo projectforSpring Boot</description> <parent> <groupId>org.springframework.boot</groupId> The < artifactId > spring - the boot - starter - parent < / artifactId > < version > 1.5.2. RELEASE < / version > < relativePath / > <! -- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> < project. Reporting. OutputEncoding > utf-8 < / project. Reporting. OutputEncoding > < Java version > 1.8 < / Java version > </properties> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-consul-discovery</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope>
        </dependency>
    </dependencies>
 
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Dalston.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
 
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
 
 
</project><br>Copy the code

Add @enableDiscoveryClient to their file ConsulMiyaApplication to enable service discovery:

@SpringBootApplication
@EnableDiscoveryClient
@RestController
public class ConsulMiyaApplication {
 
    @RequestMapping("/hi")
    public String home() {
        return "hi ,i'm miya";
    }
 
    public static void main(String[] args) {
        new SpringApplicationBuilder(ConsulMiyaApplication.class).web(true).run(args); }}Copy the code

Yml specifies port 8500 for consul in its configuration file application.yml:

spring:
  cloud:
    consul:
      host: localhost
      port: 8500
      discovery:
        healthCheckPath: ${management.contextPath}/health
        healthCheckInterval: 15s
        instance-id: consul-miya
  application:
    name: consul-miya
server:
  port: 8502<br>Copy the code

Start the project, access localhost:8500 and find that Y-Miya has been registered.

These are some of my experiences with projects or architectures. Without further ado, here is the code structure of the entire architecture:

System services

2. Generic components

Business services

Spring Cloud large enterprise distributed micro service Cloud to build B2B2C e-commerce platform source code please add penguin beg: 10387746626