@ -25,6 +25,7 @@ spring:
### Maven Dependency
### Maven Dependency
```xml
```xml
< dependency >
< dependency >
< groupId > com.tencent.cloud< / groupId >
< groupId > com.tencent.cloud< / groupId >
< artifactId > spring-cloud-starter-tencent-metadata-transfer< / artifactId >
< artifactId > spring-cloud-starter-tencent-metadata-transfer< / artifactId >
@ -62,10 +63,10 @@ java -jar ${app.jar}
Launch application, change ${app.jar} to jar's package name.
Launch application, change ${app.jar} to jar's package name.
### Metadata Configuration
### Metadata Configuration
- In the ```bootstrap.yml``` configuration file of the ```spring-cloud-tencent-examples/metadata-transfer-example/metadata-frontend``` project
- In the ```bootstrap.yml``` configuration file of
the ```spring-cloud-tencent-examples/metadata-transfer-example/metadata-frontend``` project
```yaml
```yaml
spring:
spring:
@ -77,7 +78,7 @@ spring:
# Example: intransitive
# Example: intransitive
CUSTOM-METADATA-KEY-LOCAL: CUSTOM-VALUE-LOCAL
CUSTOM-METADATA-KEY-LOCAL: CUSTOM-VALUE-LOCAL
# Example: transitive
# Example: transitive
CUSTOM-METADATA-KEY-TRANSITIVE: CUSTOM-VALUE-TRANSITIVE
CUSTOM-METADATA-KEY-TRANSITIVE: CUSTOM-VALUE-TRANSITIVE-FRONTEND
# Example: disposable
# Example: disposable
CUSTOM-METADATA-KEY-DISPOSABLE: CUSTOM-VALUE-DISPOSABLE-FRONTEND
CUSTOM-METADATA-KEY-DISPOSABLE: CUSTOM-VALUE-DISPOSABLE-FRONTEND
# Assigned which metadata key-value will be passed along the link
# Assigned which metadata key-value will be passed along the link
@ -89,7 +90,8 @@ spring:
```
```
- In the ```bootstrap.yml``` configuration file of the ```spring-cloud-tencent-examples/metadata-transfer-example/metadata-middle``` project
- In the ```bootstrap.yml``` configuration file of
the ```spring-cloud-tencent-examples/metadata-transfer-example/metadata-middle``` project
```yaml
```yaml
spring:
spring:
@ -110,7 +112,6 @@ spring:
# Specify which metadata key value will be passed only once (one-step)
# Specify which metadata key value will be passed only once (one-step)
disposable:
disposable:
- CUSTOM-METADATA-KEY-DISPOSABLE
- CUSTOM-METADATA-KEY-DISPOSABLE
```
```
### Verify
### Verify
@ -126,7 +127,7 @@ Expected return rate
```
```
{
{
"frontend-transitive-metadata": {
"frontend-transitive-metadata": {
"CUSTOM-METADATA-KEY-TRANSITIVE": "CUSTOM-VALUE-TRANSITIVE"
"CUSTOM-METADATA-KEY-TRANSITIVE": "CUSTOM-VALUE-TRANSITIVE-FRONTEND "
},
},
"frontend-upstream-disposable-metadata": {
"frontend-upstream-disposable-metadata": {
},
},
@ -135,7 +136,7 @@ Expected return rate
},
},
"middle-transitive-metadata": {
"middle-transitive-metadata": {
"CUSTOM-METADATA-KEY-TRANSITIVE": "CUSTOM-VALUE-TRANSITIVE",
"CUSTOM-METADATA-KEY-TRANSITIVE": "CUSTOM-VALUE-TRANSITIVE-FRONTEND ",
"CUSTOM-METADATA-KEY-TRANSITIVE-2": "CUSTOM-VALUE-TRANSITIVE-2"
"CUSTOM-METADATA-KEY-TRANSITIVE-2": "CUSTOM-VALUE-TRANSITIVE-2"
},
},
"middle-upstream-disposable-metadata": {
"middle-upstream-disposable-metadata": {
@ -146,7 +147,7 @@ Expected return rate
},
},
"backend-transitive-metadata": {
"backend-transitive-metadata": {
"CUSTOM-METADATA-KEY-TRANSITIVE": "CUSTOM-VALUE-TRANSITIVE",
"CUSTOM-METADATA-KEY-TRANSITIVE": "CUSTOM-VALUE-TRANSITIVE-FRONTEND ",
"CUSTOM-METADATA-KEY-TRANSITIVE-2": "CUSTOM-VALUE-TRANSITIVE-2"
"CUSTOM-METADATA-KEY-TRANSITIVE-2": "CUSTOM-VALUE-TRANSITIVE-2"
},
},
"backend-upstream-disposable-metadata": {
"backend-upstream-disposable-metadata": {
@ -162,14 +163,16 @@ Response value description
> `*` (asterisk), representing `frontend` , `middle` , `backend` in the example.
> `*` (asterisk), representing `frontend` , `middle` , `backend` in the example.
- Key `*-transitive-metadata` represents all the passable (fully linked) metadata configured by default in the service.
- Key `*-transitive-metadata` represents all the passable (fully linked) metadata configured by default in the service.
- Key `*-upstream-disposable-metadata` indicates the one-time transmissible metadata obtained from upstream requests in the service.
- Key `*-upstream-disposable-metadata` indicates the one-time transmissible metadata obtained from upstream requests in
- Key `*-local-disposable-metadata` indicates the one-time metadata passed downstream as configured by the current service.
the service.
- Key `*-local-disposable-metadata` indicates the one-time metadata passed downstream as configured by the current
service.
### How to get the passed metadata via Api
### How to get the passed metadata via Api
- Get the metadata passed globally
- Get the metadata passed globally
```java
```
MetadataContext context=MetadataContextHolder.get();
MetadataContext context=MetadataContextHolder.get();
Map< String , String > customMetadataMap=context.getFragmentContext(MetadataContext.FRAGMENT_TRANSITIVE);
Map< String , String > customMetadataMap=context.getFragmentContext(MetadataContext.FRAGMENT_TRANSITIVE);
@ -180,7 +183,7 @@ customMetadataMap.forEach((key, value) -> {
- Get disposable(one-time) metadata passed from upstream
- Get disposable(one-time) metadata passed from upstream
```java
```
Map< String , String > upstreamDisposableMetadatas=MetadataContextHolder.getAllDisposableMetadata(true);
Map< String , String > upstreamDisposableMetadatas=MetadataContextHolder.getAllDisposableMetadata(true);
upstreamDisposableMetadatas.forEach((key,value)->{
upstreamDisposableMetadatas.forEach((key,value)->{
// ...
// ...
@ -189,14 +192,14 @@ upstreamDisposableMetadatas.forEach((key, value) -> {
- Get disposable(one-time) metadata for local configuration
- Get disposable(one-time) metadata for local configuration
```java
```
Map< String , String > localDisposableMetadatas=MetadataContextHolder.getAllDisposableMetadata(false);
Map< String , String > localDisposableMetadatas=MetadataContextHolder.getAllDisposableMetadata(false);
localDisposableMetadatas.forEach((key,value)->{
localDisposableMetadatas.forEach((key,value)->{
// ...
// ...
});
});
```
```
### Wiki Reference
### Wiki Reference
See [Spring Cloud Tencent Metadata Transfer Usage Document ](https://github.com/Tencent/spring-cloud-tencent/wiki/Spring-Cloud-Tencent-Metadata-Transfer-Usage-Document ) for more reference .
See [Spring Cloud Tencent Metadata Transfer Usage Document ](https://github.com/Tencent/spring-cloud-tencent/wiki/Spring-Cloud-Tencent-Metadata-Transfer-Usage-Document )
for more reference.