-
Notifications
You must be signed in to change notification settings - Fork 9
faq cse
- 逻辑隔离和发现
Spring Cloud Alibaba的Nacos有namespace等概念支持逻辑隔离, CSE也支持应用隔离和环境隔离,不同的应用和环境是无法相互发现的,配置也支持不同的下发维度。配置项:
server:
# 默认为空, 可以配置 production, testing, development等
env: production
spring:
application:
# 微服务名称
name: basic-provider
cloud:
servicecomb:
discovery:
# 应用名称。应用名称相同的微服务可以相互调用。 否则不能发现调用。 配置也可以定义应用生效,或者全局生效。
appName: basic-application
serviceName: ${spring.application.name}
- CSE对于接口个数的限制
微服务注册失败,提示请求体太大。报错如下:
2021-10-21 10:49:39,524 ERROR ServiceCenterRegistration:145 -register microservice failed, and will try again.
org.apache.servicecomb.service.center.client.exception.OperationException: register service fails, statusCode = 400; message = Bad Request; content = {"errorCode":"400001","errorMessage":"Invalid parameter(s)","detail":"http: request body too large"}
报错原因swagger大小超限,解决方案为暂时不启用swagger。可以通过排除swagger依赖解决如下内容:
<dependency>
<groupId>com.huaweicloud</groupId>
<artifactId>spring-cloud-starter-huawei-service-engine</artifactId>
<exclusions>
<exclusion>
<groupId>com.huaweicloud</groupId>
<artifactId>spring-cloud-starter-huawei-swagger</artifactId>
</exclusion>
</exclusions>
</dependency>
Nacos通过namespace、data-id等概念指定一个微服务能够使用哪些配置,通过这些概念,用户可以管理一些微服务共用的配置,以及针对某一个微服务的独特配置。 CSE配置管理的概念和Nacos不同,CSE可以创建应用配置,这些应用配置默认下发到相同应用名称的所有微服务;微服务配置则下发到应用名称和微服务名称都相同的微服务;CSE还可以创建自定义配置,这些配置下发到哪个微服务,由微服务自己在配置文件确定:
spring:
cloud:
servicecomb:
config:
kie:
# 默认值是public
customLabel: public
# 默认值是空字符串
customLabelValue: default
当微服务配置了 customLabel 和 customLabelValue 后, 配置中心的配置项如果存在label key = customLabel 并且 label value = customLabelValue, 那么这个配置会下发到该微服务。
- 包含占位符的配置项
如果配置文件的配置项使用了占位符,并且占位符的值需要从配置中心获取, 那么这个配置项不能放到bootstrap.yaml文件, 需要放到应用配置文件,比如 application.yaml, 否则会报无法解析占位符的异常。
- List对象配置绑定
有些业务使用了List对象配置绑定,例如:
@ConfigurationProperties("example.complex")
public class ComplexConfigurationProperties {
private List<String> stringList;
private List<Model> modelList;
// ... ...
}
对于List对象,Spring Cloud默认都只会从一个PropertySource查询相关的配置项, 如果其中一个PropertySource存在配置项的部分值,那么不会再查询其他值。 因此,在使用List对象绑定的时候,和这些List属性相关的配置,都必须全部放到配置中心, 不支持部分元素在配置文件,部分元素在配置中心的场景。可以将这个约束理解为“List配置的原子性”, 即一个配置项(代码例子中的stringList或者modelList)不能被分割在不同的配置文件,保证配置项的原子性。
Spring Cloud Alibaba集成Sentinel以后, 可以通过实现一个 GlobalFilter, 集成sentinel的功能。 Spring Cloud Huawei也可以使用基于动态配置的流量特征治理 。 基本开发流程非常简单,只需要在路由Filter中使用该功能即可
spring:
main:
web-application-type: reactive
cloud:
gateway:
routes:
- id: basic-consumer
uri: lb://basic-consumer
filters:
## 使用基于动态配置的流量特征治理
- name: governance
predicates:
- Path=/**
- 使用动态配置的方式下发流控规则
## rate limiting configuration
servicecomb:
matchGroup:
allOperation: |
matches:
- apiPath:
prefix: "/"
rateLimiting:
allOperation: |
rate: 100
流控规则也可以统一放到配置文件,通过配置中心下发, 也可以通过CSE服务治理功能进行交互式创建。
- 微服务开发框架迁移概述
- Spring Cloud Gateway迁移CSE
- Zuul迁移CSE
-
Nacos+Spring Cloud迁移CSE
- 使用migrator完成一键式改造
- migrator改造步骤详细说明
-
Eureka+Spring Cloud迁移CSE
- 使用migrator完成一键式改造
- migrator改造步骤详细说明
-
HSF迁移Spring Cloud
- 使用migrator完成一键式改造
- migrator改造步骤详细说明
-
Dubbo迁移Spring Cloud
- 使用migrator完成一键式改造
- migrator改造步骤详细说明
- 常见问题
- 为migrator项目贡献代码