0

Imagine you have a Postgres database. The driver in use is blocking. To move the resource access into reactive world, you wrap the blocking call in a Mono:

Mono.fromSupplier { repository.find(id) }

According to the r2dbc docs the connection itself is wrapped in a Mono when using the driver:

Mono.from(connectionFactory.create())
  .flatMapMany(connection -> ..)
  .flatMap(result -> ..)
  .subscribe();

Is the resulting behaviour identical to using a reactive driver like R2DBC? If not, what difference does it make?

nykon
  • 504
  • 4
  • 18
  • 1
    Once your lambda started in your first snippet, it cannot be "paused"/"parked". I.e it is not cooperative. As it does not use any reactive operation, Reactor only see a black box that will run in one shot. I expect R2DBC to use reactive/pausable operations as much as possible. In your example, you load a single item, so there's not really any problems with streaming of result or backpressure. But for long-running queries loading a lot of rows/documents, I expect R2DBC to respect back-pressure guarantees where with jdbc, it is more difficult to simulate. – amanin Dec 12 '22 at 07:52

0 Answers0