Reactor REST Mono returns ScanAvailable: true

Viewed 4319

I've been working on a Java microservice that uses Reactor in order to make asynchronous calls easier. On my endpoint I have the following code:

@HystrixCommand
@ApiOperation(value = "Resolve Dispute")
@PostMapping(consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE, path = "/resolve")
public Mono<RestResponse<RestResponseResult>> resolveDispute(@RequestBody ResolveDisputeRequest requestJson, @RequestParam("appToken") String appToken) {
    if (apiAppToken.equals(appToken)) {
        EnumsUtils.getEnumValue(DisputeReason.values(), requestJson.getResolutionType(), requestJson);
        return facebookApiService.resolveDispute(requestJson).single();
    } else {
        throw new InvalidTokenException(requestJson.getUserId());
    }
}

Which I would expect to return an object

{
    result: true/false
}

However, as I inspect the code, I realize that a response is issued before the code finishes its' process. The response given is:

{
  "scanAvailable": true
} 

Which leads me to believe that this has to do with the asynchronous nature of Reactor, but doesn't suit my needs.

How should I properly use Reactor in order to obtain the required response? I do not wish to use block method which makes the call blocking.

Thanks in advance for any provided help.

All the best,

Alejandro

3 Answers

I face the some problem with aspectj weaving.

The response {"scanAvailable":true} is from mono.map(x -> joinPoint.proceed()), and it should be mono.flatMap(x -> (Mono) joinPoint.process()).

is this a reactive code or immediate EnumsUtils.getEnumValue(DisputeReason.values(), requestJson.getResolutionType(), requestJson); ?

We have encountered the same issue and it turned to be a wrong lib import:

My import:

import io.micrometer.shaded.reactor.core.publisher.Flux
import io.micrometer.shaded.reactor.core.publisher.Mono

It should be:

import reactor.core.publisher.Flux
import reactor.core.publisher.Mono
Related