I have a simple aspect (see below) with @Around
annotation. This aspect works when the the application don't use reactive paradigm. But when the application returns Mono or Flux doesn't works properly.
I need to get the object returned from the method to generate a JSON object to use as log, generate events, etc.
Here is my code that works in a non reactive classes:
@Around("@annotation(simpleEvent)")
public Object logExecutionTime(ProceedingJoinPoint joinPoint, SimpleEvent simpleEvent) throws Throwable {
final long start = System.currentTimeMillis();
Object proceed = null;
try {
proceed = joinPoint.proceed();
// here in the real life the object that transformed in json to do others actions
System.out.println(proceed);
final long executionTime = System.currentTimeMillis() - start;
System.out.println(joinPoint.getSignature() + " executed in " + executionTime + "ms");
return proceed;
} catch (Exception e) {
e.printStackTrace();
}
return proceed;
}
How to get the object returned from joinPoint.proceed()
when is Mono or Flux?
Thanks in advance.
Flux
or aMono
represent a deferred computation. Such a method usually immediately returns, with an "inert"Mono
which will be triggered once something calls one of itssubscribe
methods, so that kind of aspect isn't adapted anymore. – Simon Baslé