0

I am trying to map through a mono and return a value from its field but that block is not getting called for some reason? I am trying to return a string from the method, I wonder if that is where I am going wrong and if it should be something else?

public String function getId(String name, Flux<Shift> shifts){
Mono<Shift> shift= shifts.filter(s-> s.getName().equals(name)).singleOrEmpty();

shift.map(u-> { 
   System.out.println("gets to here");

   if(u.getId()!=null){
      return u.getId()
   }

   return null;

   })

return null;
}

I dont see the print statement which means that bit of the code is not reached. Any help would be appreciated...

1 Answer 1

1

You are configuring the reactor, but not executing it.

If this is the end of the reactive part, you can change it to

return shift.map(u-> { 
   System.out.println("gets to here");

   if(u.getId()!=null){
      return u.getId()
   }

   return null;

   })
   .block();

Otherwise, consider changing the return type of the method to Mono<String>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.