华为云ServiceComb学习记录-持续更新

发布于 2019-11-14  6151 次阅读


CSE与SpringCloud差异化

1、需改启动类注解@EnableServiceComb

2、需改@RestController注解为@RestSchema

  1. 通过RestSchema替换RestController。
  2. 需要显示声明@RequestMapping。

3、禁用DispatcherServletAutoConfiguration

@SpringBootApplication(exclude=DispatcherServletAutoConfiguration.class)

4、SpringCloud Fegin替换为 cse restful

5、SpringCloud 替换成 service-center

6、SpringCloud Config 替换为 service-config

7、SpringCloud Gateway 替换为 Edge Service

8、无法使用HttpServletRequest和HttpServletResponse、@RequestBody

9、如果controller类名上不定义RequestMapping时,系统自动使用类名作为默认值

私有仓库配置巨坑:

华为变更了cse sdk仓库路径

目前仅Java SDK已经发布到maven仓库中,maven仓库地址为https://mirrors.huaweicloud.com/repository/maven/huaweicloudsdk/,配置maven源的方法可参见https://bbs.huaweicloud.com/forum/forum.php?mod=viewthread&tid=1779

<repository>
    <id>HuaweiCloudSDK</id>
   <url>https://mirrors.huaweicloud.com/repository/maven/huaweicloudsdk/</url>
    <releases>
        <enabled>true</enabled>
    </releases>
    <snapshots>
        <enabled>false</enabled>
    </snapshots>
</repository>


报错说明

不开启开发模式得话,service中增加接口的话,会提示Caused by: java.lang.IllegalStateException: The schema(id=[hello]) content held by this instance and the service center is different. You need to increment microservice version before deploying. Or you can configure service_description.environment=development to work in development environment and ignore this error

解决办法:

  1. 增加微服务的版本,也就是要修改microservice.yaml配置文件里的service_description.version配置项的值
  2. 将环境更改为开发环境,也就是在microservice.yaml配置文件里加上一个配置 service_description.environment=development

配置文件说明

cse-config-order: 100

APPLICATION_ID: spring-boot
service_description:
  name: spring-boot-simple
  version: 0.0.1
  environment: development  #设置为开发模式,如果不是开发者模式。当微服务接口变动时,启动会报错。
  properties:
    allowCrossApp: true  #设置为false时,外部系统无法访问接口

cse:

# for local test 
# 连接公有服务中心
  service:
    registry:
      address: https://cse.cn-north-4.myhuaweicloud.com
      instance:
        watch: false
        healthCheck:
          interval: 5

# for cloud service 
#  config:
#    client:
#      refreshMode: 1
#  service:
#    registry:
#      address: https://cse.cn-north-1.myhwclouds.com:443
#      instance:
#        watch: false
# 连接公有配置中心
  config:
    client:
      serverUri: https://cse.cn-north-4.myhuaweicloud.com/
      refreshMode: 1
      refresh_interval: 15000
#  monitor:
#    client:
#      serverUri: https://cse.cn-north-1.myhwclouds.com:443
#  credentials:
#    accessKey: your access key
#    secretKey: your secret key
#    akskCustomCipher: default

# 服务映射网卡及端口
  rest:
    address: 0.0.0.0:8080

# 服务中心认证信息
  credentials:
    accessKey: xxxxxxxxxxx
    secretKey: xxxxxxxxxxx
    akskCustomCipher: default #默认不加密
    project: cn-north-4 #使用公共服务注册中心时需要配置
# 线下开发,关闭监控数据上报
  monitor:
    client:
      enable: false
#小坑,配置文件中配置了对应的urlPattern的话,访问的时候得带上
servicecomb:
  rest:
    servlet:
      urlPattern: /*
server:
  port: 9999

公共服务注册地址:https://cse.cn-north-4.myhuaweicloud.com使用公共服务注册中心得时候,需要配置相应得project


个人博客,用于记录工作日常的问题。