spring-webfluxreactivespring-webclient

Duplicate request sent by `org.springframework.web.reactive.function.client.WebClient`


This is the piece of code that sends the requests twice every time you call it

 suspend fun requestSimulation(simulationRequest: SimulationRequest): Boolean {
        val accepted = WebClient.create(simulationServiceHost)
            .post()
            .uri(simulationEndpoint)
            .bodyValue(simulationRequest)
            .retrieve()
            .bodyToFlux(Boolean::class.java)

        accepted.subscribe { bool: Boolean -> logger.info(bool.toString()) }
        return accepted.awaitSingle()
    }

Solution

  • This is the modified code that fixed the issue

    suspend fun requestSimulation(simulationRequest: SimulationRequest): Boolean {
            return WebClient.create(simulationServiceHost)
                .post()
                .uri(simulationEndpoint)
                .bodyValue(simulationRequest)
                .retrieve()
                .bodyToMono(Boolean::class.java)
                .awaitSingle()
        }