4

I have some microservices, which should work on top of WebFlux framework. Each server has own API with Mono or Flux. We are using MongoDB, which is supported by Spring (Spring Data MongoDb Reactive).

The problem is external blocking API, which I have to use in my system.

I have one solution. I can just wrap blocking API calls in dedicated thread pool and use it with CompletableFuture.

Is there anything else to solve my problem? I think, that brand new Rsocket cannot solve my problem.

Max
  • 1,803
  • 3
  • 25
  • 39
  • By blocking API you mean a simple http request-response type API? A reactive HTTP client exists for spring https://docs.spring.io/spring-framework/docs/5.0.0.M1/spring-framework-reference/html/web-reactive.html. – David Szalai Oct 08 '18 at 07:56
  • @DavidSzalai yea, I mean simple http request-response type API. – Max Oct 08 '18 at 17:18
  • I understand. Then a reactive web client as I linked could be used if it uses non-blocking IO (you should check this out, but I think it does). A dedicated threadpool and wrapping blocking api calls with futures does not make it non-blocking if you think about it. It just outsources the 'blocking' part to another thread pool. The whole purpose of non-blocking in simple terms is to do not wait for the response, but be notified when it arrives (e.g. in form of an event), so it requires some low level OS coordination. – David Szalai Oct 09 '18 at 12:09

3 Answers3

1

1.If possible, you can change your blocking API call to the reactive way using the WebClient class.

References:

  1. Reference guide
  2. WebClient API
  3. A simple, complete sample

2.If the blocking API can't be changed to reactive ones, we should have a dedicated, well-tuned thread pool and isolate the blocking code there. There is also an example here.

chao_chang
  • 778
  • 8
  • 14
0

I don't see why you cannot wrap a blocking API call in a Flux or a Mono. You can also integrate Akka with Spring if the actor model seems easier to you.

Glenn
  • 7,874
  • 3
  • 29
  • 38
0

RSocket should be a perfect fit, good tutorials to get you started

https://www.baeldung.com/spring-boot-rsocket

https://spring.io/blog/2020/04/06/getting-started-with-rsocket-spring-boot-channels

Yuri Schimke
  • 12,435
  • 3
  • 35
  • 69