【全栈之路】微服务课程5_Eureka入门

架构图

简介

Eureka是Netflix开源的服务发现组件,本身是一个基于REST的服务,包含Server和Client两部分,Spring Cloud将它集成在子项目Spring Cloud Netflix中。GitHub:https://github.com/Netflix/Eu...

项目创建

【全栈之路】微服务课程5_Eureka入门_第1张图片

【全栈之路】微服务课程5_Eureka入门_第2张图片

【全栈之路】微服务课程5_Eureka入门_第3张图片

核心代码-Eureka Server

pom.xm

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

application.yml

server:
  port: 8761
eureka:
  client:
    # 是否要注册到其他Eureka Server实例
    register-with-eureka: false
    # 是否要从其他Eureka Server实例获取数据
    fetch-registry: false
    service-url:
      defaultZone: http://localhost:8761/eureka/

ShopDiscoveryEurekaApplication.java

package com.dream.shop;

        import org.springframework.boot.SpringApplication;
        import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@EnableEurekaServer
public class ShopDiscoveryEurekaApplication {

    public static void main(String[] args) {
        SpringApplication.run(ShopDiscoveryEurekaApplication.class, args);
    }

}

核心代码-Eureka Client

pom.xml


  org.springframework.cloud
  spring-cloud-starter-netflix-eureka-client

application.yml

spring:
  application:
    # 指定注册到eureka server上的服务名称,对于电影微服务,本系列将名称设为shop-provider-user
    name: shop-provider-user

eureka:
  client:
    service-url:
      # 指定eureka server通信地址,注意/eureka/小尾巴不能少
      defaultZone: http://localhost:8761/eureka/
  instance:
    # 是否注册IP到eureka server,如不指定或设为false,那就会注册主机名到eureka server
    prefer-ip-address: true

测试

http://localhost:8761

【全栈之路】微服务课程5_Eureka入门_第4张图片

你可能感兴趣的:(springcloud,springboot)