Axel
11/09/2023, 1:21 PM@RestController
@RequestMapping("/v1/sensors")
class UpdateSensorEndpoint(
private val updateSensor: UpdateSensor
) {
@PutMapping("/{sensorId}")
internal suspend fun updateSensor(
@PathVariable("sensorId") sensorId: Long,
@RequestBody request: SensorUpdateDto
): Mono<ResponseEntity<Unit>> {
Mono.fromCallable { updateSensor.update(sensorId, request) }
.subscribeOn(Schedulers.boundedElastic())
.subscribe()
return Mono.just(ResponseEntity.ok().build())
}
}
Is this the best way to accept a request, return 200OK immediately and perform processing in the background?
I need to achieve a few thousand concurrent requests to this endpoint. The update()
method could take roughly 500ms-1s to completeashmelev
11/09/2023, 3:19 PMAxel
11/09/2023, 3:20 PMashmelev
11/09/2023, 3:22 PMDaniel Pitts
11/09/2023, 7:04 PMashmelev
11/09/2023, 7:06 PMDaniel Pitts
11/09/2023, 7:10 PMExecutor
, rather than Mono.fromCallable
and subscribeOn
.kqr
11/09/2023, 8:07 PMDaniel Pitts
11/09/2023, 8:08 PMDavio
11/09/2023, 8:52 PMCharles Flynn
11/11/2023, 9:29 AMAxel
11/13/2023, 7:48 AMcorneil
11/21/2023, 10:26 AM