Simple to understand Eureka

1, Eureka Introduction 

  Eureka is Spring Cloud Netflix part of the micro-service suite, is a mature service registration and discovery component, may Springboot build micro-services easily integrate.

  Eureka including server and client components

    Server for service registration server

    The client is a Java client to simplify interaction with the server, the polling as the failure load balancer, and provide support services to switch

2, Springcloud parent project required dependencies

 

 1 <parent>
 2         <groupId>org.springframework.boot</groupId>
 3         <artifactId>spring-boot-starter-parent</artifactId>
 4         <version>2.0.7.RELEASE</version>
 5         <relativePath/>
 6     </parent>
 7     <properties>
 8         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 9         <maven.compiler.source>1.8</maven.compiler.source>
10         <maven.compiler.target>1.8</maven.compiler.target>
11         <junit.version>4.12</junit.version>
12         <spring-cloud.version>Finchley.SR2</spring-cloud.version>
13     </properties>
14     <!--依赖声明-->
15     <dependencyManagement>
16         <dependencies>
17             <dependency>
18                 <groupId>org.springframework.cloud</groupId>
19                 <artifactId>spring-cloud-dependencies</artifactId>
20                 <version>${spring-cloud.version}</version>
21                 <type>pom</type>
22                 <scope>import</scope>
23             </dependency>
24             <dependency>
25                 <groupId>org.mybatis.spring.boot</groupId>
26                 <artifactId>mybatis-spring-boot-starter</artifactId>
27                 <version>1.3.2</version>
28             </dependency>
29             <dependency>
30                 <groupId>com.alibaba</groupId>
31                 <artifactId>druid</artifactId>
32                 <version>1.1.12</version>
33             </dependency>
34             <dependency>
35                 <groupId>mysql</groupId>
36                 <artifactId>mysql-connector-java</artifactId>
37                 <version>8.0.13</version>
38             </dependency>
39             <dependency>
40                 <groupId>junit</groupId>
41                 <artifactId>junit</artifactId>
42                 <version>${junit.version}</version>
43                 <scope>test</scope>
44             </dependency>
45 
46             <dependency>
47                 <groupId>org.projectlombok</groupId>
48                 <artifactId>lombok</artifactId>
49                 <version>1.18.10</version>
50                 <scope>provided</scope>
51             </dependency>
52         </dependencies>
53     </dependencyManagement>

 

3, sub-project of a properties.yml file

. 1  Server:
 2    Port: 8001
 . 3  MyBatis:
 . 4    config-LOCATION: CLASSPATH: MyBatis / mybatis.cfg.xml # MyBatis the path profile
 . 5    type-aliases- Package : com.offcn.springcloud.entity # alias classes where all Entity package
 6    Mapper-locations: the CLASSPATH: the mybatis / Mapper / ** /*.xml Mapper mapping file #
 7  the Spring:
 8    the Application:
 9      name: microService-Product # this is very important, which call each other after the service and between services according to this usually name
 10    DataSource:
 . 11      type: com.alibaba.druid.pool.DruidDataSource # operation type the current data source
 12     driver-class-name: com.mysql.cj.jdbc.Driver # mysql driver package
 13 is      URL: JDBC: MySQL: //127.0.0.1: 3306 / GMT Day3 serverTimezone =% # 2B8 database name?
 14      username: the root
 15      password : the root
 16      dbcp2:
 . 17        min-IDLE:. 5 # database connection pool minimum holding connections
 18 is        Initial-size:. 5 # initialization connections
 . 19        max-Total:. 5 # maximum number of connections
 20 is        max-the wait-of millis: 150 # wait connections to obtain the maximum timeout
 21  Eureka:
 22    instance:
 23      hostname: EurekaServer01
 24-    Client:
 25      the Register-with-Eureka: EurekaServer to true # this is not registered to other registries
 26     fetch-registry: true # do not pull the server information from other centers Center
 27      Service-url:
 28        defaultzone: HTTP: // localhost : 6001 / Eureka /, http://eureka6001.com : 6001 / Eureka # registry access address

4, another file

1  # built tomcat service start listening port number
 2  Server:
 . 3    Port: 8888
 . 4  # Name application
 . 5  Spring:
 . 6    file application:
 . 7      name: EurekaServer01
 . 8  #EurekaServer arranged
 . 9  Eureka:
 10    Client:
 . 11      Register-with-Eureka: to false # this EurekaServer not registered to other registration center
 12 is      fETCH Registry-: to false        # not pull information from other server centers center
 13 is      Service- URL:
 14        defaultzone: HTTP: // localhost: $ {} the server.port / Eureka Registry # address

5, complete code did not upload, attach too much here GitHub address https://github.com/Leo-12/springboot.git

 

 

Guess you like

Origin www.cnblogs.com/lifefamily/p/11816533.html