Skip to content

Commit 07663a9

Browse files
authored
Merge pull request #93 from reactivegroup/feature/develop
feature: optimize rpc code
2 parents b61b80d + a42a08b commit 07663a9

File tree

15 files changed

+268
-111
lines changed

15 files changed

+268
-111
lines changed

examples/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,16 @@
2323
<parent>
2424
<artifactId>capa-parent</artifactId>
2525
<groupId>group.rxcloud</groupId>
26-
<version>1.10.12.2.RELEASE</version>
26+
<version>1.11.13.RELEASE</version>
2727
</parent>
2828

2929
<artifactId>capa-examples</artifactId>
3030
<packaging>jar</packaging>
3131
<name>capa-sdk-examples</name>
3232

3333
<properties>
34-
<log4j.version>2.16.0</log4j.version>
34+
<log4j.version>2.17.0</log4j.version>
3535
<logback.version>1.2.3</logback.version>
36-
<slf4j-api.version>1.7.32</slf4j-api.version>
3736
</properties>
3837

3938
<dependencies>
@@ -72,6 +71,7 @@
7271
<artifactId>logback-classic</artifactId>
7372
<version>${logback.version}</version>
7473
</dependency>
74+
7575
<!--lombok-->
7676
<dependency>
7777
<groupId>org.projectlombok</groupId>

pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<groupId>group.rxcloud</groupId>
2424
<artifactId>capa-parent</artifactId>
2525
<packaging>pom</packaging>
26-
<version>1.10.12.2.RELEASE</version>
26+
<version>1.11.13.RELEASE</version>
2727
<name>capa-sdk-parent</name>
2828
<description>SDK for Capa.</description>
2929
<url>https://github.com/reactivegroup</url>
@@ -81,7 +81,7 @@
8181
<java.version>8</java.version>
8282
<file.encoding>UTF-8</file.encoding>
8383
<maven.version>3.8.1</maven.version>
84-
<cloud-runtimes.version>1.0.10.RELEASE</cloud-runtimes.version>
84+
<cloud-runtimes.version>1.11.RELEASE</cloud-runtimes.version>
8585
<reactor-core.version>3.3.22.RELEASE</reactor-core.version>
8686
<slf4j.version>1.7.21</slf4j.version>
8787
<grpc.version>1.39.0</grpc.version>
@@ -440,4 +440,5 @@
440440
</plugin>
441441
</plugins>
442442
</build>
443+
443444
</project>

sdk-component/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<parent>
2424
<groupId>group.rxcloud</groupId>
2525
<artifactId>capa-parent</artifactId>
26-
<version>1.10.12.2.RELEASE</version>
26+
<version>1.11.13.RELEASE</version>
2727
</parent>
2828

2929
<artifactId>capa-sdk-component</artifactId>
@@ -33,7 +33,7 @@
3333
<properties>
3434
<okhttp.version>4.9.1</okhttp.version>
3535
<kotlin-stdlib.version>1.4.10</kotlin-stdlib.version>
36-
<log4j.version>2.16.0</log4j.version>
36+
<log4j.version>2.17.0</log4j.version>
3737
<logback.version>1.2.3</logback.version>
3838
</properties>
3939

sdk-component/src/main/java/group/rxcloud/capa/component/telemetry/context/CapaContextPropagatorBuilder.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ public ContextPropagators buildContextPropagators() {
6767
List<String> types = contextConfig.getContextPropagators();
6868
if (types != null && !types.isEmpty()) {
6969
types.stream()
70-
.map(path -> SpiUtils
71-
.newInstanceWithConstructorCache(path, TextMapPropagator.class))
70+
.map(path -> SpiUtils.newInstanceWithConstructorCache(path, TextMapPropagator.class))
7271
.forEach(propagator -> propagators.add(propagator));
7372
}
7473
}

sdk-infrastructure/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<parent>
2424
<artifactId>capa-parent</artifactId>
2525
<groupId>group.rxcloud</groupId>
26-
<version>1.10.12.2.RELEASE</version>
26+
<version>1.11.13.RELEASE</version>
2727
</parent>
2828

2929
<artifactId>capa-sdk-infrastructure</artifactId>

sdk-infrastructure/src/main/java/group/rxcloud/capa/infrastructure/utils/SpiUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
* Load class and create instance from config file.
4141
* TODO move to {@link CapaProperties}
4242
*/
43+
@Deprecated
4344
public final class SpiUtils {
4445

4546
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper()

sdk-spi-demo/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
<parent>
2424
<artifactId>capa-parent</artifactId>
2525
<groupId>group.rxcloud</groupId>
26-
<version>1.10.12.2.RELEASE</version>
26+
<version>1.11.13.RELEASE</version>
2727
</parent>
2828

2929
<artifactId>capa-sdk-spi-demo</artifactId>
3030
<packaging>jar</packaging>
3131
<name>capa-sdk-spi-demo</name>
3232

3333
<properties>
34-
<log4j.version>2.16.0</log4j.version>
34+
<log4j.version>2.17.0</log4j.version>
3535
<logback.version>1.2.3</logback.version>
3636
</properties>
3737

sdk-spi/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
<parent>
2424
<artifactId>capa-parent</artifactId>
2525
<groupId>group.rxcloud</groupId>
26-
<version>1.10.12.2.RELEASE</version>
26+
<version>1.11.13.RELEASE</version>
2727
</parent>
2828

2929
<artifactId>capa-sdk-spi</artifactId>
3030
<packaging>jar</packaging>
3131
<name>capa-sdk-spi</name>
3232

3333
<properties>
34-
<log4j.version>2.16.0</log4j.version>
34+
<log4j.version>2.17.0</log4j.version>
3535
<logback.version>1.2.3</logback.version>
3636
</properties>
3737

sdk-spi/src/main/java/group/rxcloud/capa/spi/http/CapaHttpSpi.java

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import group.rxcloud.capa.component.http.CapaHttp;
2020
import group.rxcloud.capa.component.http.HttpResponse;
21+
import group.rxcloud.capa.infrastructure.exceptions.CapaErrorContext;
22+
import group.rxcloud.capa.infrastructure.exceptions.CapaException;
2123
import group.rxcloud.capa.infrastructure.serializer.CapaObjectSerializer;
2224
import group.rxcloud.capa.spi.http.config.CapaSpiOptionsLoader;
2325
import group.rxcloud.capa.spi.http.config.CapaSpiProperties;
@@ -63,16 +65,16 @@ protected <T> CompletableFuture<HttpResponse<T>> doInvokeApi(String httpMethod,
6365
TypeRef<T> type) {
6466
if (logger.isDebugEnabled()) {
6567
if (httpMethod != null) {
66-
logger.debug("[CapaHttpSpi] invoke rpc httpMethod[{}]", httpMethod);
68+
logger.debug("[Capa.Rpc.Client.http] [CapaHttpSpi] invoke rpc httpMethod[{}]", httpMethod);
6769
}
6870
if (urlParameters != null && !urlParameters.isEmpty()) {
69-
logger.debug("[CapaHttpSpi] invoke rpc urlParameters[{}]", urlParameters);
71+
logger.debug("[Capa.Rpc.Client.http] [CapaHttpSpi] invoke rpc urlParameters[{}]", urlParameters);
7072
}
7173
if (headers != null && !headers.isEmpty()) {
72-
logger.debug("[CapaHttpSpi] invoke rpc headers[{}}]", headers);
74+
logger.debug("[Capa.Rpc.Client.http] [CapaHttpSpi] invoke rpc headers[{}}]", headers);
7375
}
7476
if (context != null) {
75-
logger.debug("[CapaHttpSpi] invoke rpc context[{}]", context);
77+
logger.debug("[Capa.Rpc.Client.http] [CapaHttpSpi] invoke rpc context[{}]", context);
7678
}
7779
}
7880

@@ -84,45 +86,32 @@ protected <T> CompletableFuture<HttpResponse<T>> doInvokeApi(String httpMethod,
8486
final String _method = pathSegments[3];
8587
final String method = pathSegments[4];
8688
if (logger.isDebugEnabled()) {
87-
logger.debug("[CapaHttpSpi] invoke rpc url_path[/version={}/{}/appId={}/{}/methodName={}]",
89+
logger.debug("[Capa.Rpc.Client.http] [CapaHttpSpi] invoke rpc url_path[/version={}/{}/appId={}/{}/methodName={}]",
8890
version, _invoke, appId, _method, method);
8991
}
9092

9193
// load spi service options
9294
RpcServiceOptions rpcServiceOptions = getRpcServiceOptions(appId);
9395
Objects.requireNonNull(rpcServiceOptions, "rpcServiceOptions");
9496
if (logger.isDebugEnabled()) {
95-
logger.debug("[CapaHttpSpi] invoke rpc options[{}]",
97+
logger.debug("[Capa.Rpc.Client.http] [CapaHttpSpi] invoke rpc options[{}]",
9698
rpcServiceOptions);
9799
}
98100

99-
// spi invoke
100-
CompletableFuture<HttpResponse<T>> invokeSpiApi =
101-
invokeSpiApi(appId, method, requestData, httpMethod, headers, urlParameters, type, rpcServiceOptions);
102-
invokeSpiApi.whenComplete((tHttpResponse, throwable) -> {
103-
if (throwable != null) {
104-
if (logger.isWarnEnabled()) {
105-
logger.warn("[CapaHttpSpi] invoke rpc response error",
106-
throwable);
107-
}
108-
return;
109-
}
110-
if (tHttpResponse == null) {
111-
if (logger.isWarnEnabled()) {
112-
logger.warn("[CapaHttpSpi] invoke rpc response empty[{}]",
113-
tHttpResponse);
114-
}
115-
return;
101+
try {
102+
// spi invoke
103+
CompletableFuture<HttpResponse<T>> invokeSpiApi = invokeSpiApi(
104+
appId, method, requestData, httpMethod, headers, urlParameters, type, rpcServiceOptions);
105+
invokeSpiApi.whenComplete(this::callbackLog);
106+
return invokeSpiApi;
107+
} catch (CapaException e) {
108+
throw e;
109+
} catch (Exception e) {
110+
if (logger.isErrorEnabled()) {
111+
logger.error("[Capa.Rpc.Client.http] [CapaHttpSpi] invoke error, un-catch throwable is: ", e);
116112
}
117-
final int responseStatusCode = tHttpResponse.getStatusCode();
118-
final Map<String, String> responseHeaders = tHttpResponse.getHeaders();
119-
final T responseBody = tHttpResponse.getBody();
120-
if (logger.isDebugEnabled()) {
121-
logger.debug("[CapaHttpSpi] invoke rpc response code[{}] headers[{}] body[{}]",
122-
responseStatusCode, responseHeaders, responseBody);
123-
}
124-
});
125-
return invokeSpiApi;
113+
throw new CapaException(CapaErrorContext.SYSTEM_ERROR, e);
114+
}
126115
}
127116

128117
/**
@@ -136,6 +125,35 @@ protected RpcServiceOptions getRpcServiceOptions(String appId) {
136125
return capaSpiOptionsLoader.loadRpcServiceOptions(appId);
137126
}
138127

128+
private <T> void callbackLog(HttpResponse<T> tHttpResponse, Throwable throwable) {
129+
if (throwable != null) {
130+
if (throwable instanceof CapaException) {
131+
return;
132+
}
133+
// un-catch throwable
134+
else {
135+
if (logger.isErrorEnabled()) {
136+
logger.error("[Capa.Rpc.Client.http.callback] [CapaHttpSpi] invoke rpc response error",
137+
throwable);
138+
}
139+
return;
140+
}
141+
}
142+
if (tHttpResponse == null) {
143+
if (logger.isWarnEnabled()) {
144+
logger.warn("[Capa.Rpc.Client.http.callback] [CapaHttpSpi] invoke rpc response empty.");
145+
}
146+
return;
147+
}
148+
final int responseStatusCode = tHttpResponse.getStatusCode();
149+
final Map<String, String> responseHeaders = tHttpResponse.getHeaders();
150+
final T responseBody = tHttpResponse.getBody();
151+
if (logger.isDebugEnabled()) {
152+
logger.debug("[Capa.Rpc.Client.http.callback] [CapaHttpSpi] invoke rpc response code[{}] headers[{}] body[{}]",
153+
responseStatusCode, responseHeaders, responseBody);
154+
}
155+
}
156+
139157
/**
140158
* Invoke spi api and then return async completable future.
141159
*

0 commit comments

Comments
 (0)