spring cloud 分布式实战(二)-- Eureka

Eureka

Spring Cloud Eureka 是 微服务套件中的一部分,它基于Netflix Eureka 做了二次封装,主要负责完成微服务架构中的服务治理功能

两大核心

Eureka - server

顾名思义,就是服务注册中心

pom
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-eureka-server</artifactId>             
    </dependency>
配置文件
server:
  port: 8081

eureka:
  instance:
    hostname: localhost
  client: 
    # 作为服务发现中心必要配置,区别于服务提供者
    register-with-eureka: false
    # 作为服务发现中心必要配置,区别于服务提供者
    fetch-registry: false
    service-url: 
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
启动类
@EnableEurekaServer
@SpringBootApplication
public class EurekaApplication
{
    public static void main(String[] args)
    {
        SpringApplication.run(EurekaApplication.class, args);
    }
}

Eureka - client

是服务提供方,注册到server中

pom
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
        </dependency>
配置文件
spring:
  application:
    name: haha-auth
server:
  port: 8083

eureka:
  client: 
    service-url: 
      defaultZone: http://localhost:8081/eureka/
启动类
@EnableEurekaClient
@SpringBootApplication
public class AuthApplication
{
    public static void main(String[] args)
    {
        SpringApplication.run(AuthApplication.class, args);
    }
}
校验,先启动server项目,在启动client项目。访问server项目地址

本例地址: http://127.0.0.1:8081/
这里写图片描述

如图,即可成功使用eureka。图中红色部分,我单独讲解。优化是一步步的过程
附: 本例所有代码,均托管在码云,撸码不易,多多支持,谢谢大家。
项目地址: 戳这里

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值