I am newly on project-reactor based reactive framework like spring-webflux and I have a few question about it.
Question 1:
Example 1:
public Mono<String> doSome(String str){
String key = str.substring(0, 5).toLowerCase() + str.substring(6);
return getValueFromRedis(key);
}
public Mono<String> getValueFromRedis(String key){
return reactiveRedisOperations().opsForHash().get("TestCache", key);
}
Example 2:
public Mono<String> doSome(String str){
return Mono.fromCallable(() -> {
String key = str.substring(0, 5).toLowerCase() + str.substring(6);
return getValueFromRedis(key);
}).flatMap(stringMono -> stringMono);
}
public Mono<String> getValueFromRedis(String key){
return reactiveRedisOperations().opsForHash().get("TestCache", key);
}
is there a difference between with two example or both of them are acceptable.
Question 2:
Example 1:
@PostMapping(value = "/greet")
public Mono<String> greet(String name) {
return Mono.fromCallable(() -> aMethod(name));
// or return Mono.just(aMethod(name));
}
public String aMethod(String name){
return "Hello: " + name;
}
Example 2:
@PostMapping(value = "/greet")
public Mono<String> greet(String name) {
return aMethod(name);
}
public Mono<String> aMethod(String name){
return Mono.just("Hello: " + name);
}
Second question is weird I know but I'm wonder all of method should return Mono or Flux or can I use like Question2/Example1.