注册中心Eureka

注册中心Eureka

eureka的依赖 
 <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
​
eureka的配置文件
spring:
  application:
    name: eureka-server
server:
  port: 8001
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8001/eureka/
    fetch-registry: false     #禁止当前项目写入eureka服务中
    register-with-eureka: false
  server:
    enable-self-preservation: false  #关闭自我保护机制
    eviction-interval-timer-in-ms: 4000 #剔除时间

register-with-eureka: false false表示不向注册中心注册自己

fetch-registry: false false表示自己就是注册中心,不需要从注册中心获取注册列表信息

service-url 设置eureka server交互的地址查询服务和注册服务都需要用到这个地址(单机用)

主启动类
@SpringBootApplication
@EnableEurekaServer // 声明当前springboot应用是一个eureka服务中心
public class EurekaApp {
    public static void main(String[] args) {
        SpringApplication.run(EurekaApp.class);
    }
}

搭建生产者Provider

引入依赖

在这里插入图片描述

  <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
​
<!--        在provider的pom文件中添加监控依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
    </dependencies>

server:
  port: 9070
spring:
  application:
    name: user-server
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8001/eureka/
  instance:
    prefer-ip-address: true
    instance-id: ${spring.cloud.client.ip-address}:${server.port} #显示注册的ip和端口
    lease-renewal-interval-in-seconds: 5    #心跳时间
    lease-expiration-duration-in-seconds: 20 #续约时间
order-provider:
  ribbon:
    NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RandomRule
management:   #hystrix的数据流文件,存储监控数据
  endpoints:
    web:
      exposure:
        include: hystrix.stream
主启动类
@SpringBootApplication
@EnableEurekaClient // 或 @EnableDiscoveryClient
public class ProviderApp {
    public static void main(String[] args) {
        SpringApplication.run(ProviderApp.class);
    }
}

@EnableEurekaClient和@EnableDiscoveryClient区别 在使用Spring Cloud feign使用中在使用服务发现的时候提到了两种注解: 一种为@EnableDiscoveryClient; 一种为@EnableEurekaClient,用法上基本一致

  • 22
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值