简体   繁体   中英

R2DBC - how it works in reality?

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM