I have a simple Spring cloud Stream function
package com.example
@Configuration
public class Processor {
@Bean
public Function<Message<String>, Message<String>> mapper() {
return msg -> {
// do stuff
};
}
}
I want to log the input message and the output message transparently.
I tried @GlobalChannelInterceptor
exactly as suggested in this answer, but with not luck. Both the input and output messages are intercepted in the preSend
postSend
afterSendCompletion
methods after the function is completed.
I also tried using AspectJ as follows:
@Slf4j
@Aspect
@Component
public class MyAspect {
@Before("execution(* com.example.Processor.*(..)) && args(message,..)")
public void logBefore(JoinPoint joinPoint, Message<?> message) {
log.info("before {}", message);
}
@Around("execution(* com.example.Processor.*(..)) && args(message,..)")
public Object logAround(ProceedingJoinPoint joinPoint, Message<?> message) throws Throwable {
log.info("around {}", message);
return joinPoint.proceed();
}
@After("execution(* com.example.Processor.*(..)) && args(message,..)")
public void logAfter(JoinPoint joinPoint, Message<?> message) {
log.info("after {}", message);
}
}
But this hooks are never called. No logs are shown and I can't hit them with debugger.
Any suggestions on how I can log around Spring Cloud Functions?