R2DBC - how it works in reality?

525 views Asked by At

I've started to learn Reactive paradigm, so I'm pretty new in this topic. I created a sample app which uses Spring R2DBC to connect to PostgreSQL DB.

I created a Rest Controller for fetching and saving data in DB to better understand a concept.

I expected to meet the following scenario:

  1. I'm running findById query from reactive repository class looking for id, which does not exist in DB yet. I'm subscribing on the returned Mono object
  2. I'm saving the entity with id queried in (1)
  3. Query from (1) is constantly listening for changes in DB and finds added entity immediately

Unfortunately it does not work in such way. Basically point no (3) is never happening and I need to fire query from (1) manually to hit the DB again.

My question is - am I doing something wrong or understanding reactive database concept incorrectly?

I feel, needing some explanation here. I really appreciate your help at this issue.

1

There are 1 answers

1
Hantsy On BEST ANSWER

Genrally,I think http connection and database connection will release the connection after execution is done.

But for your cases list here, it is not diffcult to implement in Spring Reactive stack.

I have created some samples using a tailable Mongo document.

For R2dbc, you can use Sinks or Processors to replay the payload (when it is saved) and sent to the client, check this branch.

And you can also ultilze Postgres Notificaiton to implement similar featuers, check this question.