• 简单了解Eureka


    1、Eureka简介 

      EurekaSpring Cloud Netflix微服务套件中的一部分,是一套成熟的服务注册和发现组件,可以与Springboot构建的微服务很容易的整合起来。

      Eureka包含服务器端和客户端组件

        服务器用于服务注册服务器

        客户端是一个Java客户端,用来简化与服务器的交互,作为轮询负载均衡器,并提供服务的故障切换支持

    2、Springcloud父工程需要的依赖文件

     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、子工程的一个properties.yml文件

     1 server:
     2   port: 8001
     3 mybatis:
     4   config-location: classpath:mybatis/mybatis.cfg.xml # mybatis配置文件所在路径
     5   type-aliases-package: com.offcn.springcloud.entity # 所有Entity别名类所在包
     6   mapper-locations: classpath:mybatis/mapper/**/*.xml # mapper映射文件
     7 spring:
     8   application:
     9     name: microservice-product #这个很重要,这在以后的服务与服务之间相互调用一般都是根据这个name
    10   datasource:
    11     type: com.alibaba.druid.pool.DruidDataSource # 当前数据源操作类型
    12     driver-class-name: com.mysql.cj.jdbc.Driver # mysql驱动包
    13     url: jdbc:mysql://127.0.0.1:3306/day3?serverTimezone=GMT%2B8 # 数据库名称
    14     username: root
    15     password: root
    16     dbcp2:
    17       min-idle: 5 # 数据库连接池的最小维持连接数
    18       initial-size: 5 # 初始化连接数
    19       max-total: 5 # 最大连接数
    20       max-wait-millis: 150 # 等待连接获取的最大超时时间
    21 eureka:
    22   instance:
    23     hostname: EurekaServer01
    24   client:
    25     register-with-eureka: true #此EurekaServer不在注册到其他的注册中心
    26     fetch-registry: true       #不在从其他中心中心拉取服务器信息
    27     service-url:
    28       defaultZone: http://localhost:6001/eureka/,http://eureka6001.com:6001/eureka #注册中心访问地址

    4、另一个文件

     1 #内置的tomcat服务启动监听端口号
     2 server:
     3   port: 8888
     4 #应用名称
     5 spring:
     6   application:
     7     name: EurekaServer01
     8 #EurekaServer配置
     9 eureka:
    10   client:
    11     register-with-eureka: false #此EurekaServer不在注册到其他的注册中心
    12     fetch-registry: false       #不在从其他中心中心拉取服务器信息
    13     service-url:
    14       defaultZone: http://localhost:${server.port}/eureka #注册中心访问地址

    5、完整的代码没上传,太多这里附上GitHub地址https://github.com/Leo-12/springboot.git

  • 相关阅读:
    迅为i.MX8M开发板Linux安卓9.0系统,四核CortexA53,单核CortexM4
    迅为龙芯2K1000开发板虚拟机ubuntu安装SSH服务
    迅为i.MX8MM开发板虚拟机Vmware的安装
    迅为龙芯2K1000开发板虚拟机ubuntu安装vscode
    归并排序XCoderLiu
    关于API中窗口子类化及超类化整理
    STL中最流行类模板vector
    andbook
    Navigation Failed: Cannot Find Application\HTML\1033\default.htm 错误解决办法
    html 播放音乐
  • 原文地址:https://www.cnblogs.com/lifefamily/p/11816533.html
Copyright © 2020-2023  润新知