微服务治理系列二

2021-12-31  本文已影响0人  架构师老狼

注册中心Nacos

1 主流注册中心对比

主流注册中心对比

2 CAP实践

AP与CP

配置中心Nacos:

1 bootstrap.yaml配置

2 配置规则

{spring.application.name}-{spring.profiles.active}.${spring.cloud.nacos.config.file-extension}

3 springcloud原生注解@RefreshScope+nacos动态刷新配置

@RestController
@RefreshScope //支持Nacos的动态刷新功能。
public class ConfigClientController
{
    @Value("${config.info}")
    private String configInfo;

    @GetMapping("/config/info")
    public String getConfigInfo() {
        return configInfo;
    }
}

4 配置版本回滚

nacos会记录配置文件的历史版本默认保留30天,此外还有一键回滚功能,回滚操作将触发配置更新

5 持久化存储到mysql

6 nacos集群配置

服务调用与负载均衡 OpenFeign

1 open feign

2 调用超时熔断

# feign 配置
feign:
  sentinel:
    enabled: true
  okhttp:
    enabled: true
  httpclient:
    enabled: false
  client:
    config:
      default:
        connectTimeout: 10000
        readTimeout: 10000
  compression:
    request:
      enabled: true
    response:
      enabled: true

3 open feign调用异常抽取

@FeignClient(contextId = "remoteUserService", value = ServiceNameConstants.SYSTEM_SERVICE, fallbackFactory = RemoteUserFallbackFactory.class)
public interface RemoteUserService {
    @GetMapping("/user/info/{username}")
    public R<LoginUser> getUserInfo(@PathVariable("username") String username, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
}

4 负载均衡

5 设置open feign调用详细日志

import feign.Logger;

@Configuration
public class FeignConfig{
@Bean
Logger.Level feignLoggerLevel() {
    return Logger.Level.FULL;
}
}

# yaml
logging:
level:
# feign日志以什么级别监控哪个接口
com.ruoyi.system.api.RemoteUserService: debug

分布式事务seata

1 核心概念

2 执行流程

3 原理

一阶段
二阶段-回滚
二阶段-提交
上一篇 下一篇

猜你喜欢

热点阅读