I want to write a Rest API using reactive and achieve the below result. I've 2 microservices for this.
Service 1: Receives a post Object and retrieves some data from its database. The process something then communicate to the second Micro Service. Then return the Service 2 response as a Mono to the client.
Service 2: Receives the Data passed from Service 1 and save it to database and returns the Object with the generated primary key.
Here is my code look like.
@PostMapping("/submitData")
public Mono<Object> submitScore(@RequestBody SomeObject someObject){
//Some Operations
return contestGiftInfoRepository.findAllDataById(id)
.filter(c -> {
if(condition) {
return true;
} else {
return false;
}
}).reduce((item1,item2) -> {
if(condition) {
return item1;
}else {
return item2;
}
})
.defaultIfEmpty(emptyObj)
.map(resultObj->{
//DoSome OPeration
WebClient client = WebClient.create("my service Url 2");
Mono<Obj> response = client.post().uri("/ExecutionPath")
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.body(Mono.just(resultObj), ResultObj.class)
.retrieve()
.bodyToMono(ResponseObj.class);
return response;
});
}
Now When I call the web service 1 everything works fine. When I call the second web service individually that works as well. However, when I call the second web service from the first service it returns a result reactor.core.Exceptions$ErrorCallbackNotImplemented: org.springframework.web.reactive.function.client.WebClientResponseException$InternalServerError: 500 Internal Server Error from POST http://localhost:8085/path Caused by: org.springframework.web.reactive.function.client.WebClientResponseException$InternalServerError: 500 Internal Server Error from POST http://localhost:8085/path at org.springframework.web.reactive.function.client.WebClientResponseException.create(WebClientResponseException.java:218) ~[spring-webflux-5.3.16.jar:5.3.16] Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: Error has been observed at the following site(s):
I don't understand the actual issue from the error message. What I'm missing here?