project-reactor

How to log request and response bodies in Spring WebFlux

元气小坏坏 提交于 2019-11-27 14:21:58
I want to have centralised logging for requests and responses in my REST API on Spring WebFlux with Kotlin. So far I've tried this approaches @Bean fun apiRouter() = router { (accept(MediaType.APPLICATION_JSON) and "/api").nest { "/user".nest { GET("/", userHandler::listUsers) POST("/{userId}", userHandler::updateUser) } } }.filter { request, next -> logger.info { "Processing request $request with body ${request.bodyToMono<String>()}" } next.handle(request).doOnSuccess { logger.info { "Handling with response $it" } } } Here request method and path log successfully but the body is Mono , so how

Correct way of throwing exceptions with Reactor

杀马特。学长 韩版系。学妹 提交于 2019-11-27 09:52:48
问题 I'm new to project Reactor and reactive programming in general. I'm currently working on a piece of code similar to this: Mono.just(userId) .map(repo::findById) .map(user-> { if(user == null){ throw new UserNotFoundException(); } return user; }) // ... other mappings This example is probably silly and there are surely better ways of implementing this case, but the point is: Is it wrong to use a throw new exception in a map block or should I replace this with a return Mono.error(new

Reactive Programming Advantages/Disadvantages

人走茶凉 提交于 2019-11-26 19:44:42
问题 I keep studying and trying Reactive Style of coding using Reactor and RxJava. I do understand that reactive coding makes better utilization of CPU compared to single threaded execution. Is there any concrete comparison between reactive programming vs imperative programming in web based applications? How much is the performance gain, throughput I achieve by using reactive programming over non-reactive programming? Also what are the advantages and disadvantages of Reactive Programming? Is there

How to log request and response bodies in Spring WebFlux

元气小坏坏 提交于 2019-11-26 11:08:18
问题 I want to have centralised logging for requests and responses in my REST API on Spring WebFlux with Kotlin. So far I\'ve tried this approaches @Bean fun apiRouter() = router { (accept(MediaType.APPLICATION_JSON) and \"/api\").nest { \"/user\".nest { GET(\"/\", userHandler::listUsers) POST(\"/{userId}\", userHandler::updateUser) } } }.filter { request, next -> logger.info { \"Processing request $request with body ${request.bodyToMono<String>()}\" } next.handle(request).doOnSuccess { logger