I'm a beginner in Spring Web flux and in java Stream. I need to call a method that returns a Mono twice depending on the result content of the first call. But I don't know how to make it works and how to respect best practices i.e not to have 2 return statements in my method.
Off course the code below does not work but I want to show the kind of behaviour that I would like to have. But Don't know how to have it in a Stream way...
@Slf4j
@Service
public class Compare {
@Autowired
Myservice myService;
public Mono<MyResponse> compute(String firstItem,String secondItem, String thirdItem){
// First Comparison between firstItem and secondItem
Mono<MyResponse> firstResponse = myService.sendRequestToCompare(firstItem,secondItem);
firstResponse.subscribe(result -> { // Issue on the subscribe method according to my IDE
if ((result.getResponse().getStatus().toString() == "NOT_SAME") && (result.getResponse().getErrorCode() == 201)) {
// Second Comparison with a third value if the previous first one does not match
Mono<MyResponse> secondResponse = myService.sendRequestToCompare(firstItem,thirdItem);
return secondResponse; // Error raised in IDE says change to return; or change method retrun type to Mono<MyResponse> which is already the case
break;
}
}, error -> {
log.error("The following error happened on getResponse method from myService!", error);
});
return firstResponse;
}
}