Skip to content

Commit 2552a1b

Browse files
committed
reactify-core
1 parent 0bff0f6 commit 2552a1b

File tree

109 files changed

+388
-920
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+388
-920
lines changed

reactify-core/pom.xml

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
3-
Copyright 2024-2025 the original author Hoàng Anh Tiến.
3+
Copyright 2024-2025 the original author Hoàng Anh Tiến
44
55
Licensed under the Apache License, Version 2.0 (the "License");
66
you may not use this file except in compliance with the License.
@@ -23,13 +23,20 @@
2323
<version>3.3.5</version>
2424
<relativePath/>
2525
</parent>
26+
27+
<!-- =========================================== -->
28+
<!-- The maven central for all the library -->
29+
<!-- =========================================== -->
2630
<groupId>io.github.hoangtien2k3</groupId>
2731
<artifactId>reactify-core</artifactId>
28-
<version>1.2.5</version>
32+
<version>1.2.6</version>
2933
<name>reactify-core</name>
3034
<description>Java library for developing reactive programming(reactor-core) backend systems in microservices</description>
3135
<url>https://github.com/hoangtien2k3/reactify-core</url>
3236

37+
<!-- =========================================== -->
38+
<!-- The info developers for all the library -->
39+
<!-- =========================================== -->
3340
<licenses>
3441
<license>
3542
<name>Apache License, Version 2.0</name>
@@ -60,12 +67,14 @@
6067
</repository>
6168
</distributionManagement>
6269

70+
<!-- =========================================== -->
71+
<!-- The properties for all the library -->
72+
<!-- =========================================== -->
6373
<properties>
6474
<java.version>21</java.version>
6575
<micrometer.tracing.version>1.4.3</micrometer.tracing.version>
6676
<micrometer.registry.version>1.4.3</micrometer.registry.version>
6777
<micrometer.core.version>1.14.4</micrometer.core.version>
68-
<spring-cloud.version>2023.0.2</spring-cloud.version>
6978
<spotless.version>2.43.0</spotless.version>
7079
<log4j.version>2.23.1</log4j.version>
7180
<minio.version>8.5.11</minio.version>
@@ -94,18 +103,9 @@
94103
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
95104
</properties>
96105

97-
<dependencyManagement>
98-
<dependencies>
99-
<dependency>
100-
<groupId>org.springframework.cloud</groupId>
101-
<artifactId>spring-cloud-dependencies</artifactId>
102-
<version>${spring-cloud.version}</version>
103-
<type>pom</type>
104-
<scope>import</scope>
105-
</dependency>
106-
</dependencies>
107-
</dependencyManagement>
108-
106+
<!-- =========================================== -->
107+
<!-- The dependencies for all the library -->
108+
<!-- =========================================== -->
109109
<dependencies>
110110
<dependency>
111111
<groupId>org.springframework.boot</groupId>
@@ -210,6 +210,9 @@
210210
</dependency>
211211
</dependencies>
212212

213+
<!-- =========================================== -->
214+
<!-- The plugins for all the library -->
215+
<!-- =========================================== -->
213216
<build>
214217
<plugins>
215218
<plugin>

reactify-core/src/main/java/com/reactify/annotations/LocalCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024-2025 the original author Hoàng Anh Tiến.
2+
* Copyright 2024-2025 the original author Hoàng Anh Tiến
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

reactify-core/src/main/java/com/reactify/annotations/LogPerformance.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024-2025 the original author Hoàng Anh Tiến.
2+
* Copyright 2024-2025 the original author Hoàng Anh Tiến
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

reactify-core/src/main/java/com/reactify/annotations/Loggable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024-2025 the original author Hoàng Anh Tiến.
2+
* Copyright 2024-2025 the original author Hoàng Anh Tiến
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

reactify-core/src/main/java/com/reactify/annotations/cache/CacheAspect.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024-2025 the original author Hoàng Anh Tiến.
2+
* Copyright 2024-2025 the original author Hoàng Anh Tiến
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

reactify-core/src/main/java/com/reactify/annotations/cache/CacheStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024-2025 the original author Hoàng Anh Tiến.
2+
* Copyright 2024-2025 the original author Hoàng Anh Tiến
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

reactify-core/src/main/java/com/reactify/annotations/cache/CacheUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024-2025 the original author Hoàng Anh Tiến.
2+
* Copyright 2024-2025 the original author Hoàng Anh Tiến
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

reactify-core/src/main/java/com/reactify/annotations/cache/CustomizeRemovalListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024-2025 the original author Hoàng Anh Tiến.
2+
* Copyright 2024-2025 the original author Hoàng Anh Tiến
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

reactify-core/src/main/java/com/reactify/annotations/logging/LoggerAspect.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024-2025 the original author Hoàng Anh Tiến.
2+
* Copyright 2024-2025 the original author Hoàng Anh Tiến
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
1515
*/
1616
package com.reactify.annotations.logging;
1717

18+
import lombok.RequiredArgsConstructor;
1819
import org.aspectj.lang.ProceedingJoinPoint;
1920
import org.aspectj.lang.annotation.Around;
2021
import org.aspectj.lang.annotation.Aspect;
@@ -52,18 +53,10 @@
5253
*/
5354
@Aspect
5455
@Configuration
56+
@RequiredArgsConstructor
5557
public class LoggerAspect {
56-
private final LoggerAspectUtils loggerAspectUtils;
5758

58-
/**
59-
* Constructs a new instance of {@code LoggerAspect}.
60-
*
61-
* @param loggerAspectUtils
62-
* the utility class for logging aspects.
63-
*/
64-
public LoggerAspect(LoggerAspectUtils loggerAspectUtils) {
65-
this.loggerAspectUtils = loggerAspectUtils;
66-
}
59+
private final LoggerAspectUtils loggerAspectUtils;
6760

6861
/**
6962
* <p>
@@ -73,7 +66,7 @@ public LoggerAspect(LoggerAspectUtils loggerAspectUtils) {
7366
*/
7467
@Pointcut("execution(* com.reactify.*.controller..*(..)) || " + "execution(* com.reactify.*.service..*(..)) || "
7568
+ "execution(* com.reactify.*.repository..*(..)) || " + "execution(* com.reactify.*.client..*(..)) && "
76-
+ "!execution(* org.springframework.boot.actuate..*(..)) && " + "!within(com.reactify.*.config..*)")
69+
+ "!execution(* org.springframework.boot.actuate..*(..))")
7770
public void performancePointCut() {}
7871

7972
/**

reactify-core/src/main/java/com/reactify/annotations/logging/LoggerAspectUtils.java

Lines changed: 63 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024-2025 the original author Hoàng Anh Tiến.
2+
* Copyright 2024-2025 the original author Hoàng Anh Tiến
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -123,11 +123,11 @@ public Mono<Object> logAround(ProceedingJoinPoint joinPoint) throws Throwable {
123123

124124
Span newSpan = tracer.nextSpan().name(name);
125125
var result = joinPoint.proceed();
126-
if (result instanceof Mono) {
126+
if (result instanceof Mono<?> monoResult) {
127127
return logMonoResult(
128128
joinPoint,
129129
start,
130-
(Mono<Object>) result,
130+
monoResult.cast(Object.class),
131131
newSpan,
132132
name,
133133
logType,
@@ -136,11 +136,11 @@ public Mono<Object> logAround(ProceedingJoinPoint joinPoint) throws Throwable {
136136
logInput,
137137
title);
138138
}
139-
if (result instanceof Flux) {
139+
if (result instanceof Flux<?> fluxResult) {
140140
return logFluxResult(
141141
joinPoint,
142142
start,
143-
(Flux<Object>) result,
143+
fluxResult.cast(Object.class),
144144
newSpan,
145145
name,
146146
logType,
@@ -149,7 +149,7 @@ public Mono<Object> logAround(ProceedingJoinPoint joinPoint) throws Throwable {
149149
logInput,
150150
title)
151151
.collectList()
152-
.map(list -> (Object) list);
152+
.map(list -> list);
153153
} else {
154154
return Mono.just(result);
155155
}
@@ -264,13 +264,30 @@ private Flux<Object> logFluxResult(
264264
boolean logInput,
265265
String title) {
266266
var contextRef = new AtomicReference<Context>();
267-
return result.doFinally(
268-
o -> logPerf(contextRef, newSpan, name, start, "1", null, logType, actionType, null, title))
269-
.contextWrite(context -> {
270-
contextRef.set(context);
271-
return context;
267+
if (logInput) {
268+
Object[] args = joinPoint.getArgs();
269+
logPerf(contextRef, newSpan, name, start, "INPUT", null, logType, actionType, args, title);
270+
}
271+
return result.doOnNext(output -> {
272+
if (logOutput) {
273+
logPerf(
274+
contextRef,
275+
newSpan,
276+
name,
277+
start,
278+
"OUTPUT",
279+
null,
280+
logType,
281+
actionType,
282+
new Object[] {output},
283+
title);
284+
}
272285
})
273-
.doOnError(o -> logPerf(contextRef, newSpan, name, start, "0", o, logType, actionType, null, title));
286+
.doOnError(error ->
287+
logPerf(contextRef, newSpan, name, start, "0", error, logType, actionType, null, title))
288+
.doFinally(signalType ->
289+
logPerf(contextRef, newSpan, name, start, "1", null, logType, actionType, null, title))
290+
.contextWrite(context -> contextRef.updateAndGet(ctx -> context));
274291
}
275292

276293
/**
@@ -290,15 +307,45 @@ private Flux<Object> logFluxResult(
290307
* @param result
291308
* a string indicating the result status ("0" for success, "1" for
292309
* failure)
293-
* @param o
310+
* @param data
294311
* the output object from the method execution, may be {@code null}
295312
*/
296313
private void logPerf(
297-
AtomicReference<Context> contextRef, Span newSpan, String name, Long start, String result, Object o) {
298-
newSpan.finish();
314+
AtomicReference<Context> contextRef,
315+
Span newSpan,
316+
String name,
317+
long start,
318+
String result,
319+
Object data,
320+
String logType,
321+
String actionType,
322+
String title) {
323+
if (newSpan != null) {
324+
newSpan.finish();
325+
}
299326
long duration = System.currentTimeMillis() - start;
300327
if (duration < 50) return;
301-
logPerf.info("{} {} {} M2 {}", name, duration, result, o == null ? "-" : o.toString());
328+
329+
Context context = contextRef != null ? contextRef.get() : Context.empty();
330+
String contextInfo = context != null ? context.toString() : "-";
331+
String dataInfo = "-";
332+
if (data != null) {
333+
if (data instanceof Throwable error) {
334+
dataInfo = String.format("Error: %s - %s", error.getClass().getSimpleName(), error.getMessage());
335+
} else {
336+
dataInfo = data.toString();
337+
}
338+
}
339+
logPerf.info(
340+
"{} | {} | {} | {} | {} | {} | {} | {}",
341+
title,
342+
name,
343+
duration,
344+
result,
345+
logType,
346+
actionType,
347+
contextInfo,
348+
dataInfo);
302349
}
303350

304351
/**

0 commit comments

Comments
 (0)