springCloud

什么是SpringCloud:
在SpringBoot的基础上构建的微服务架构。
1.引入组件启动器
2.覆盖默认配置
3.在引导类上添加相应的注解

eureka组件
注册中心:服务的注册与发现
服务端:
1.引入服务端的启动器 eureka-server
2.添加配置:

 spring.application.name服务名
 eureka.client.service-url.defaultZone :http://localhost:xxx/eureka 
 eureka.server.eviction-interval-timer-in-ms:剔除无效连接时间
 eureka.server.enable-self-preservation:关闭自我保护

3.@EnableEurekaServer 开启eureka服务功能
客户端:
1.引入启动器:eureka-client
2.添加配置:

spring.application.name 客户端名
eureka.client.service-url.defaultZone :http://localhost:xxx/eureka 
eureka.instance.lease-renewal-interval-in-seconds:心跳时间
eureka.instance.lease-expiration-duration-in-seconds:过期时间
eureka.client.register-with-eureka:true/false(默认是true,是否把自己注册给eureka.)
eureka.client.fetch-registy:true/false(默认是true,是否拉取服务列表)
eureka.client.registy-interval-seconds:拉去服务的间隔时间

3.@EnableDiscoveryClient:启用Eureka客户端
ribbon组件

注册中心
覆盖默认配置

server:
  port: 10087
spring:
  application:
    name: xxxx-registry
eureka:
  client:
    service-url:
      defaultZone: http://localhost:10087/eureka/
  service:
    enable-self-preservation: false #关闭自我保护模式
    eviction-interval-timer-in-ms: 10000 #每隔10秒钟,进行一次服务列表的清理

启动类相关注解

@SpringBootApplication
@EnableEurekaServer

网关注册
覆盖默认配置

server:
  port: 10010
spring:
  application:
    name: xxx-gateway
eureka:
  client:
    service-url:
      defaultZone: http://localhost:10087/eureka
    registry-fetch-interval-seconds: 5
zuul:
  prefix: /api
  routes:
    item-service: /item/** #路由到商品微服务

启动类相关注解

@SpringBootApplication
@EnableDiscoveryClient
@EnableZuulProxy

相关业务处理的其中一个模块
覆盖默认配置

server:
  port: 8081
spring:
  application:
    name: item-service
  datasource:
    url: jdbc:mysql:///haha
    username: root
    password: root
eureka:
  client:
    service-url:
      defaultZone: http://localhost:10087/eureka
  instance:
    lease-renewal-interval-in-seconds: 5 #心跳时间
    lease-expiration-duration-in-seconds: 15 #过期时间
mybatis:
  type-aliases-package: com.xxx.item.pojo #pojo包存放于接口模块 ,pom引入接口模块依赖

启动类相关注解

@SpringBootApplication
@EnableDiscoveryClient
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值