服务治理:Spring Cloud Eureka

古城微笑少年丶 2023-07-08 05:50 73阅读 0赞
  1. 核心内容:
  2. 1. 构建服务注册中心
  3. 2. 服务注册与服务发现
  4. 3. Eureka的基础架构
  5. 4. Eureka的服务治理机制
  6. 5. Eureka的配置
  1. 首先我们来搭建服务注册中心,需先创建一个Spring Boot项目,我的命名为eureka-server
    1)接下来需在pom.xml文件引入必要的依赖内容


    4.0.0

    org.springframework.boot
    spring-boot-starter-parent
    2.0.5.RELEASE


    com.ml
    eureka-server
    eureka-server
    Demo project for Spring Boot


    1.8
    Finchley.RELEASE




    org.springframework.cloud
    spring-cloud-starter-netflix-eureka-server
    2.0.1.RELEASE






    org.springframework.cloud
    spring-cloud-dependencies
    ${ spring-cloud.version}
    pom
    import







    org.springframework.boot
    spring-boot-maven-plugin




注意:
在这里我希望跟大家说明一下,spring-boot、eureka-server以及spring-cloud的版本号对应非常重要,我也因为这个版本号的问题,因此在启动运行过程中遇到了好多的问题。
2)EurekaServerApplication.class文件需引入@EnableEurekaServer注解
作用:
用于启动服务注册中心提供给其他应用进行对话

  1. @SpringBootApplication
  2. @EnableEurekaServer
  3. public class EurekaServerApplication {
  4. public static void main(String[] args) {
  5. SpringApplication.run(EurekaServerApplication.class, args);
  6. }
  7. }

3)application.properties文件

  1. #配置服务器端口
  2. server.port=1111
  3. spring.application.name=eureka-server
  4. #指定主机名
  5. eureka.instance.hostname=localhost
  6. #是否向注册中心注册自己
  7. eureka.client.register-with-eureka=false
  8. #是否需要检索服务
  9. eureka.client.fetch-registry=false
  10. #注册中心地址
  11. eureka.client.serviceurl.defaultZone=http://localhost:1111/eureka/
  12. #是否开启自我保护机制
  13. eureka.server.enable-self-preservation=true
  14. #失效剔除时间间隔
  15. eureka.server.eviction-interval-timer-in-ms=2000

以上就完成了一个简单的服务注册中心的搭建,接下来让我们来完成服务的注册与发现服务。

发表评论

表情:
评论列表 (有 0 条评论,73人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Spring Cloud Eureka(服务治理)(2)

    1.服务发现与消费 下面来尝试构建一个服务消费者,它主要完成两个目标,发现服务以及消费服务。其中服务发现的任务由Eureka的客户端完成,而服务消费者的任务由Ribbon