0

I'm using WebFlux, and I want to log with AOP as follow:

Class LogAop {

  @AfterReturning("execution ...")
  public void configSetted() {
     // Getting username by token
     Mono<Sting> username = ReactiveSecurityContextHolder.getContext()
     .map { ... };
    
     username.subscribe ({it -> loggerin.info(it);});

  }
}

In the above code, I want to log username, but there is no log. How can I subscribe to Mono or Flux without returning to the method?

Note: Some times I want to do differnt things on subscribe data, such as saving data in db.

Morteza Malvandi
  • 1,656
  • 7
  • 30
  • 73

1 Answers1

0

This should work unless ReactiveSecurityContextHolder.getContext() doesn't emit any item.

Mono<String> username = ReactiveSecurityContextHolder.getContext()
                        .map { ... };
username.subscribe (it -> loggerin.info(it));

I'd suggest adding a log to find out:

username.log().subscribe (it -> loggerin.info(it));
lkatiforis
  • 5,703
  • 2
  • 16
  • 35