# 鏁版嵁浜у搧鐧昏鏈嶅姟

## 鏁版嵁浜у搧鐧昏鏈嶅姟浠嬬粛

鏁版嵁浜у搧鐧昏鏈嶅姟鏄暟鎹绱犳祦閫氬钩鍙扮殑鏍稿績鏈嶅姟涔嬩竴锛岄噰鐢ㄥ井鏈嶅姟璁捐鎼缓锛屼富瑕佽礋璐f暟鎹骇鍝佺櫥璁扮鐞嗐€佹暟鎹骇鍝佽璇佺鐞嗙瓑鍔熻兘銆傛暟鎹骇鍝佺櫥璁版湇鍔¢」鐩畝绉癐DA銆�

鏁版嵁浜у搧鐧昏鏈嶅姟涓昏鍖呮嫭浠ヤ笅瀛愭湇鍔℃ā鍧楋細
- 鏁版嵁浜у搧鐧昏鏈嶅姟: 鎻愪緵鏁版嵁浜у搧鐧昏銆佹煡璇€€佷慨鏀广€佸垹闄ょ瓑鍔熻兘锛屾敮鎸佹暟鎹泦銆乤pi 绛変笉鍚岀被鍨嬭祫浜х殑鐧昏涓婇摼锛屼互鍙婄敵璇蜂娇鐢ㄤ粠閾句笂鍚屾鍏朵粬鏂圭櫥璁扮殑璧勪骇
- 鏁版嵁浜у搧璁よ瘉鏈嶅姟: 鎻愪緵鏁版嵁浜у搧璁よ瘉鏈嶅姟锛屽寘鍚璇佺敵璇枫€佽璇佹煡璇€€佽璇侀€氳繃銆佽璇侀┏鍥炵瓑鍔熻兘锛屾敮鎸佸悎瑙勮璇併€佷环鍊艰璇佺瓑澶氱璁よ瘉绫诲瀷


## 鏁版嵁浜у搧鐧昏鏈嶅姟

**鏁版嵁浜у搧鐧昏鏈嶅姟锛坮egistration-service锛�** 鎻愪緵鐢ㄦ埛灏嗕笉鍚岀被鍨嬬殑鏁版嵁浜у搧锛岀櫥璁板埌閾句笂鐨勬湇鍔°€�
鐢ㄦ埛鍙互鏍规嵁鑷韩鏁版嵁浜у搧锛堝寘鎷暟鎹骇鍝佺殑鍚嶇О銆佹暟鎹妯$瓑淇℃伅锛夌殑鐗圭偣锛屾寜鐓т笉鍚岀殑鏁版嵁浜у搧绫诲瀷锛岄€氳繃姝ゆ湇鍔$櫥璁板埌閾句笂銆�
鍦ㄦ暟鎹绱犳祦閫氬钩鍙颁笂锛屽彲浠ラ€氳繃閫夋嫨宸茬粡鍦ㄩ摼涓婂悎娉曠櫥璁板悗鐨勭涓夋柟浼佷笟锛堟暟鎹骇鍝佸悎瑙勮瘎浼拌璇佸拰鏁版嵁浜у搧浠峰€艰瘎浼帮級锛屽彂璧峰搴旂殑璁よ瘉鐢宠銆�
褰撶敵璇疯璇侀€氳繃鍚庯紝璇ョ櫥璁扮殑鏁版嵁浜у搧灏变細鍦ㄩ摼涓婃嫢鏈夎嚜宸辩殑鍚堣璁よ瘉璇佹槑鍜屼环鍊艰瘎浼拌瘉鏄庛€�

涓昏鐨勬ā鍧楀涓嬫墍杩�:

- GRPC鏈嶅姟锛�
    - 鎻愪緵GRPC鏈嶅姟锛岀敤浜庣綉鍏筹紙gateway锛夊眰鐨勮浆鍙戙€�
    - 鎻愪緵GRPC鏈嶅姟锛屼笓闂ㄧ敤浜庨殣绉佽绠楋紝鏈嶅姟涓細鍖呭惈鏁版嵁搴撹繛鎺ョ瓑闅愮鏁版嵁锛屼负浜嗕繚璇佹暟鎹殑瀹夊叏鎬э紝涓嶅彲琚綉鍏冲眰璋冪敤銆�
- 涓婇摼妯″潡锛� 鎻愪緵鏁版嵁浜у搧鐧昏涓婇摼銆佺紪杈戦摼涓婃暟鎹骇鍝佸拰鍒犻櫎閾句笂鏁版嵁浜у搧绛夊姛鑳�
- 浜嬩欢璁㈤槄妯″潡锛� 鐢ㄤ簬鐩戝惉閾句笂鏁版嵁浜у搧浜嬩欢锛屽悓姝ュ叾浠栭儴缃叉柟鍦ㄥ綋鍓嶉摼涓婄櫥璁扮殑鏁版嵁浜у搧浜嬩欢銆�
- 鏁版嵁婧愯繛鎺ユā鍧楋細 棰勫厛褰曞叆鏁版嵁婧愯繛鎺ヤ俊鎭紝鐢ㄤ簬鏁版嵁浜у搧鐧昏涓旀暟鎹骇鍝佺被鍨嬩负鏁版嵁闆嗙殑鏃跺€欙紝閫夋嫨鏁版嵁婧愯繛鎺ワ紝鎷夊彇鏁版嵁婧愯〃缁撴瀯銆�

![img.png](../images/asset/asset_modules.png)

### 鏁版嵁浜у搧鐧昏妯″潡渚濊禆鍏崇郴鍥�

![img.png](../images/asset/asset_relation.png)

### 鏁版嵁浜у搧鐧昏娴佺▼鍥�

![img.png](../images/asset/asset_create.png)

鐩墠鏀寔鏁版嵁闆嗐€丄PI 涓ょ绫诲瀷鐨勬暟鎹骇鍝佺櫥璁帮紝鏈湴涓哄叾鐢熸垚鍞竴鐨勬暟鎹骇鍝佺紪鍙凤紝鐒跺悗鍜岀浉鍏充俊鎭竴璧峰啓鍏ラ摼涓娿€傚叾涓暟鎹泦绫诲瀷鐨勬暟鎹骇鍝侊紝闇€瑕佹湇鍔′腑妫€鏌ュ鐞嗗ソ鏁版嵁婧愯繛鎺ュ拰琛ㄧ粨鏋勪俊鎭紝鍙湁鏁版嵁婧愬彲鐢ㄦ墠鑳界櫥璁版垚鍔熴€�

### 鏁版嵁浜у搧缂栬緫娴佺▼鍥�

![img.png](../images/asset/asset_update.png)

鏁版嵁浜у搧鐨勭紪杈戜笉鍚屼簬鐧昏锛屽畠鐨勪笂閾惧拰鏈湴鏇存柊鏄紓姝ョ殑锛屽彧鏈夌洃鍚埌鏁版嵁浜у搧鍦ㄩ摼涓婄殑鏇存柊浜嬩欢涔嬪悗锛屾墠浼氱湡姝f洿鏂版湰鍦版暟鎹殑璁板綍銆傞€氳繃杩欑褰㈠紡锛屼繚璇佷簡澶氭柟鏈€缁堣兘鍚屾鍒版纭彲鐢ㄧ殑鏁版嵁浜у搧銆�

registration-service 鍚姩閰嶇疆鏂囦欢鏍蜂緥 registration-service.yaml 濡備笅锛�

```yaml
# ------ go-zero 鑷甫閰嶇疆 ------ 
Name: registration.rpc
ListenOn: 0.0.0.0:8082

# 褰撳墠鏈嶅姟璇锋眰瓒呮椂鏃堕棿鏄� 30s
Timeout: 30000

# 鐜锛歞ev銆乼est銆乸re銆乸rod
RpcServerConf:
  Mode: dev

Log:
  # 鏈嶅姟鍚嶇О
  ServiceName: registration-service
  # 鏃ュ織杈撳嚭鍒版枃浠�
  Mode: file
  # 鏃ュ織杈撳嚭鏂囦欢璺緞
  Path: logs
  # 鏃ュ織绾у埆
  Level: info
  # 鏄惁鍘嬬缉鏃ュ織
  Compress: true
  # 鏃ュ織淇濈暀澶╂暟锛屽彧鏈夊湪鏂囦欢妯″紡鎵嶄細鐢熸晥
  KeepDays: 30
  # 鎸夊ぉ鍒囧壊鏃ュ織
  Rotation: daily
  # 鏃ュ織鏃堕棿鏍煎紡
  TimeFormat: "2006-01-02 15:04:05"

# 鍩轰簬 OpenTelemetry 鐨勬棩蹇楁敹闆嗛摼璺拷韪�
Telemetry:
  # 閾捐矾杩借釜寮€鍏筹紝涓嶉厤缃粯璁ゆ槸寮€鍚�
  Disabled: true
  # 閾捐矾杩借釜鏈嶅姟鍚嶇О锛岃窡鏈嶅姟鍚嶇О淇濇寔涓€鑷村嵆鍙�
  Name: key.rpc
  # 閾捐矾杩借釜鏈嶅姟绔湴鍧€
  Endpoint: http://jaeger:14268/api/traces
  # 閲囨牱鐜囷紝涓嶉厤缃粯璁ゆ槸 1.0
  Sampler: 1.0
  # 鏀寔 jaeger|zipkin|otlpgrpc|otlphttp 杩欎簺閾捐矾杩借釜宸ュ叿锛屼笉閰嶇疆榛樿 jaeger
  Batcher: jaeger

# 鐩戞帶锛岄粯璁ら兘鏄紑鍚紝涓昏璋冩暣绔彛鍜岀洃鎺ц闂矾鐢�
DevServer:
  # 鐩戞帶鎸囨爣鍜屽仴搴锋鏌ョ殑鎬诲紑鍏筹紝涓嶉厤缃槸榛樿寮€鍚�
  Enable: true
  # 鐩戞帶鎸囨爣鍜屽仴搴锋鏌ョ殑绔彛
  Port: 6062
  # 鍋ュ悍妫€鏌ヨ矾鐢憋紝涓嶉厤缃槸榛樿 /healthz
  HealthPath: "/healthz"
  # 鍋ュ悍妫€鏌ヨ繑鍥烇紝涓嶉厤缃粯璁ゆ槸 OK
  HealthResponse: "OK"
  # 鐩戞帶鎸囨爣璺敱锛屼笉閰嶇疆鏄粯璁� /metrics
  MetricsPath: "/metrics"


# grpc 閫氫俊鏈嶅姟绔瘉涔︾閽�
GrpcServerConf:
  #  ServerCertFile: ./cert/registration-service/server.pem
  #  ServerKeyFile: ./cert/registration-service/server.key
  #  CaCertFile: ./cert/ca/ca.pem
  ServerCertFile:
  ServerKeyFile:
  CaCertFile:

  # 鎺ユ敹銆佸彂閫佹秷鎭ぇ灏忚缃负 20 mb锛屾牴鎹湇鍔″疄闄呭満鏅皟鏁�
  MaxRecvMsgSize: 20971520
  MaxSendMsgSize: 20971520

  # 鏁版嵁搴撹繛鎺ラ檺娴侀€熺巼
  TestDBConnRate: 10

# 鏁版嵁搴撻厤缃�
DBConf:
  # 鏁版嵁搴撶被鍨嬶紝鏀寔锛歮ysql銆乲ingbase_mysql銆乲ingbase_pgsql銆乸ostgres
  Type: "mysql"
  # 鏁版嵁搴撹繛鎺ュ瓧绗︿覆
  DNS: root:root123456@tcp(127.0.0.1:3306)/registration_service?charset=utf8&parseTime=true&loc=Asia%2FShanghai

# redis 缂撳瓨閰嶇疆锛屼富瑕佹寚瀹氳闂湴鍧€锛屽叾浠栭厤缃」榛樿鍗冲彲
Cache:
  - Host: 127.0.0.1:6379
    Pass: "123456"

# Event 閾句笂浜嬩欢
EventConf:
  Host: "127.0.0.1"
  Port: 6379
  Password: "123456"
  GroupName: "registration"
  ContractName: "ida200"
  ChainConfigInterval: 60

# ExpiredConf 杩囨湡鏃堕棿閰嶇疆
ExpiredConf:
  Internal: 300    # 妫€鏌ラ棿闅旓紝鍗曚綅绉掞紝榛樿5鍒嗛挓
  UploadInterval : 3  # 涓婇摼鏌ヨ浜ゆ槗鎵ц缁撴灉闂撮殧
  UploadMaxSeconds: 1800    # 涓婇摼瓒呮椂鏈€澶ф鏌ユ椂闂�

GrpcConfs:
  key-service:
    #    ClientCertFile: ./cert/key-service/client.pem
    #    ClientKeyFile: ./cert/key-service/client.key
    #    CaCertFile: ./cert/ca/ca.pem
    ClientCertFile:
    ClientKeyFile:
    CaCertFile:
    DNS: localhost
    Endpoint: 127.0.0.1:8083
  chain-service:
    #    ClientCertFile: ./cert/chain-service/client.pem
    #    ClientKeyFile: ./cert/chain-service/client.key
    #    CaCertFile: ./cert/ca/ca.pem
    ClientCertFile:
    ClientKeyFile:
    CaCertFile:
    DNS: localhost
    Endpoint: 127.0.0.1:8081
```


## 鏁版嵁浜у搧璁よ瘉鏈嶅姟

璁よ瘉鏈嶅姟锛坈ertification-service锛夋槸骞冲彴鐢ㄦ潵渚涜璇佷汉鍛樺畬鎴愯璇佹搷浣滅殑鍦版柟銆傚湪鏁版嵁浜у搧瀹屾垚鐧昏涓婇摼鍚庯紝鏁版嵁浜у搧鐧昏鏂瑰彲浠ュ彂璧疯璇佽姹傘€傚湪璁よ瘉璇锋眰涓婇摼鍚庯紝璁よ瘉骞冲彴鍗冲彲鏀跺埌寰呰璇佺殑璇锋眰銆� certification-servic 鏄熀浜庢祦琛岀殑 go-zero 妗嗘灦寮€鍙戠殑 gRPC 鏈嶅姟銆�

涓昏鐨勬ā鍧楀涓嬫墍杩�:
- gRPC璁块棶:瀵规帴缃戝叧渚х殑API璁块棶
- 璁よ瘉淇℃伅鏁寸悊锛�
    - 鏁寸悊鑾峰彇鍒扮殑閾句笂鏁版嵁鍒版湰鍦版暟鎹簱
    - 鍙戦€佹湰鍦板鐞嗙殑璁よ瘉淇℃伅鎺ㄩ€佸埌redis鏈嶅姟
- 璁よ瘉鏁版嵁浜у搧淇℃伅绠$悊锛�
    - 璁よ瘉鏁版嵁浜у搧淇℃伅鐨勫鍒犳敼
    - 璁よ瘉鏁版嵁浜у搧淇℃伅鐨勭姸鎬佺鐞�
- 浜嬩欢鐩戝惉锛氶€氳繃閾句笂浜嬩欢鐩戝惉锛岃嚜鍔ㄦ媺鍙栬璇佽姹�
    - 鑾峰彇璁よ瘉淇℃伅锛屽寘鎷璇佽姹傘€佸凡瀹屾垚鐨勮璇佸鎵�
    - 鑾峰彇宸蹭笂閾剧殑璁よ瘉鐩稿叧鐨勬暟鎹骇鍝佷俊鎭�
    - 鍚屾閾句笂鏁版嵁浜у搧鐘舵€佸埌鏈湴鏁版嵁搴�
- redis鏈嶅姟锛�
    - 璁よ瘉鏈嶅姟涓庨摼鏈嶅姟鐨勬秷鎭€氶亾


**鏋舵瀯璁捐鍥�**

![data_circulation_certification_architecture.png](../images/data_circulation_certification_architecture.png)

**閾句笂鏁版嵁浜у搧鐩戝惉娴佺▼鍥�**

![data_circulation_certification_apply_event.png](../images/data_circulation_certification_apply_event.png)

鏁版嵁浜у搧鐨勫悓姝ラ兘鏄€氳繃鐩戝惉閾句笂浜嬩欢鏉ュ畬鎴愶紝璁よ瘉妯″潡鍒欏彧鐢ㄨ闃呯洃鍚璇佺浉鍏崇殑浜嬩欢锛屽鏀跺埌鐨勮璇佷簨浠跺厛妫€鏌ュ搴旀暟鎹骇鍝佹槸鍚﹀瓨鍦紝鐒跺悗鍐嶆洿鏂扮浉鍏宠璇佽褰曘€�

**鏁版嵁浜у搧璁よ瘉娴佺▼鍥�**

![data_circulation_certification_handle_apply.png](../images/data_circulation_certification_handle_apply.png)

鍏锋湁璁よ瘉璧勬牸鐨勭敤鎴凤紝閫氳繃鐧诲綍鏈钩鍙版煡鐪嬪緟璁よ瘉鏁版嵁浜у搧鍒楄〃锛屽绗﹀悎瑕佹眰鐨勬暟鎹骇鍝佸彂璧疯璇佽姹傘€傜敱浜庤璇佹搷浣滀細涓婇摼锛屾墍浠ュ畠浼氳皟鐢� chain-service 妯″潡鐨勫悎绾﹁皟鐢ㄦ帴鍙f潵瀹屾垚涓婇摼銆傚悓鏍峰湴锛屾湇鍔℃湰鍦板紓姝ョ洃鍚璇佷簨浠讹紝鍙湁姝g‘鏀跺埌浜嬩欢鎵嶈涓鸿璇佷笂閾炬垚鍔燂紝杩涜€屾洿鏂版湰鍦扮殑璁よ瘉璁板綍銆�


certification-service 鍚姩閰嶇疆鏂囦欢鏍蜂緥 certification-service.yaml 濡備笅锛�

```yaml
# ------ go-zero 鑷甫閰嶇疆 ------ 
Name: certification.rpc
ListenOn: 0.0.0.0:8084

#Etcd:
#  Hosts:
#  - 127.0.0.1:2379
#  Key: certification.rpc

# 褰撳墠鏈嶅姟璇锋眰瓒呮椂鏃堕棿鏄� 30s
Timeout: 30000

# 鐜锛歞ev銆乼est銆乸re銆乸rod
Mode: prod

Log:
  # 鏈嶅姟鍚嶇О
  ServiceName: certification-service
  # 鏃ュ織杈撳嚭鍒版枃浠�
  Mode: file
  # 鏃ュ織杈撳嚭鏂囦欢璺緞
  Path: logs
  # 鏃ュ織绾у埆
  Level: info
  # 鏄惁鍘嬬缉鏃ュ織
  Compress: true
  # 鏃ュ織淇濈暀澶╂暟锛屽彧鏈夊湪鏂囦欢妯″紡鎵嶄細鐢熸晥
  KeepDays: 30
  # 鎸夊ぉ鍒囧壊鏃ュ織
  Rotation: daily

# 鍩轰簬 OpenTelemetry 鐨勬棩蹇楁敹闆嗛摼璺拷韪�
Telemetry:
  # 閾捐矾杩借釜寮€鍏筹紝涓嶉厤缃粯璁ゆ槸寮€鍚�
  #Disabled: true
  # 閾捐矾杩借釜鏈嶅姟鍚嶇О锛岃窡鏈嶅姟鍚嶇О淇濇寔涓€鑷村嵆鍙�
  Name: chain.rpc
  # 閾捐矾杩借釜鏈嶅姟绔湴鍧€
  Endpoint: http://jaeger:14268/api/traces
  # 閲囨牱鐜囷紝涓嶉厤缃粯璁ゆ槸 1.0
  Sampler: 1.0
  # 鏀寔 jaeger|zipkin|otlpgrpc|otlphttp 杩欎簺閾捐矾杩借釜宸ュ叿锛屼笉閰嶇疆榛樿 jaeger
  Batcher: jaeger

# 鐩戞帶锛岄粯璁ら兘鏄紑鍚紝涓昏璋冩暣绔彛鍜岀洃鎺ц闂矾鐢�
DevServer:
  # 鐩戞帶鎸囨爣鍜屽仴搴锋鏌ョ殑鎬诲紑鍏筹紝涓嶉厤缃槸榛樿寮€鍚�
  Enable: true
  # 鐩戞帶鎸囨爣鍜屽仴搴锋鏌ョ殑绔彛
  Port: 6064
  # 鍋ュ悍妫€鏌ヨ矾鐢憋紝涓嶉厤缃槸榛樿 /healthz
  HealthPath: "/healthz"
  # 鍋ュ悍妫€鏌ヨ繑鍥烇紝涓嶉厤缃粯璁ゆ槸 OK
  HealthResponse: "OK"
  # 鐩戞帶鎸囨爣璺敱锛屼笉閰嶇疆鏄粯璁� /metrics
  MetricsPath: "/metrics"

GrpcConf:
  #  CaCertFile: ./cert/ca/ca.pem
  #  ServerCertFile: ./cert/certification-service/server.pem
  #  ServerKeyFile: ./cert/certification-service/server.key
  CaCertFile: ""
  ServerCertFile: ""
  ServerKeyFile: ""
  # 鎺ユ敹銆佸彂閫佹秷鎭ぇ灏忚缃负 20 mb锛屾牴鎹湇鍔″疄闄呭満鏅皟鏁�
  MaxRecvMsgSize: 20971520
  MaxSendMsgSize: 20971520

# grpc 閫氫俊鏈嶅姟绔瘉涔︾閽�
GrpcConfs:
  chain-service:
    #    ClientCertFile: ./cert/chain-service/client.pem
    #    ClientKeyFile: ./cert/chain-service/client.key
    #    CaCertFile: ./cert/ca/ca.pem
    ClientCertFile: ""
    ClientKeyFile: ""
    CaCertFile: ""
    DNS: localhost
    Endpoint: 127.0.0.1:8081
  key-service:
    #    ClientCertFile: ./cert/key-service/client.pem
    #    ClientKeyFile: ./cert/key-service/client.key
    #    CaCertFile: ./cert/ca/ca.pem
    ClientCertFile: ""
    ClientKeyFile: ""
    CaCertFile: ""
    DNS: localhost
    Endpoint: 127.0.0.1:8083

# 鏁版嵁搴撻厤缃�
DBConf:
  # 鏁版嵁搴撶被鍨嬶紝鏀寔锛歮ysql銆乲ingbase_mysql銆乲ingbase_pgsql銆乸ostgres
  Type: "mysql"
  # 鏁版嵁搴撹繛鎺ュ瓧绗︿覆
  DNS: root:root123456@tcp(127.0.0.1:3306)/certification_management?charset=utf8&parseTime=true&loc=Asia%2FShanghai

EventConf:
  Host: "127.0.0.1"
  Port: 6379
  Password: "123456"
  Consumer: "certification_consumer"
  GroupName: "certification"
  ChainConfigInterval: 3600

```