SpringCloud注册中心应用及分析

本文介绍了SpringCloud中Eureka、Consul和Nacos作为注册中心的组件对比、使用方法以及如何与Feign集成。Eureka不再更新维护,Consul需要独立的服务端程序,而Nacos则提供了丰富的控制台界面。在客户端配置中,Eureka和Nacos通过注解方式简单集成,Consul需额外添加actuator依赖以确保服务状态正常。
摘要由CSDN通过智能技术生成

介绍:注册中心是微服务的重要组成之一,目前常用的有Eureka/Consule/Nacos。

模块一 组件对比:

  • Eureka是netflix公司的,也是较早出现作为注册中心的组件,2.X已不再更新维护,最新稳定版为v1.9.12,查看spring-cloud-starter-netflix-eureka-client的Maven依赖,eureka-client和eureka-core版本就是1.9.12。
    在这里插入图片描述
  • Consul组件也是可以作为注册中心来使用的,其版本是跟着SpringCloud版本版本进行维护。
  • Nacos组件是阿里巴巴的产品,是与springcloud-alibaba进行的集成,可作为注册中心使用。

模块二 组件使用:
I. Eureka:服务端和客户端都是使用容器启动的。
  ①服务端
    a 引入依赖:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>

    b 使用注解注释启动类:

@SpringBootApplication
@EnableEurekaServer
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

    c 配置不要自己注册自己配置文件:

server:
  port: 9090
eureka:
  instance:
    hostname: localhost
  client:
    register-with-eureka: false
    fetch-registry: false
  server:
   enableSelfPreservation: false

#    serviceUrl:
#      defaultZone: http://localhost:9091/eureka/

  ②客户端
    a 引入依赖,注意这里artifactId是【spring-cloud-starter-netflix-eureka-client】,低版本是【spring-cloud-starter-eureka-server】

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</a
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值