Is it possible to use both Spring Data R2DBC and Spring Data JPA in a single Spring boot application?

对着背影说爱祢 提交于 2021-01-19 06:11:51

问题


I have an application which is using Spring data JPA and hibernate envers for db auditing. Since R2DBC doesn't support auditing yet, is it possible to use combination of both in a single application?

If yes, Plan is to use Spring Data JPA for insert, update and delete operations, so that all DB auditing will be handled by hibernate envers. And use R2DBC for reactive non-blocking API's to read data.

If no, Is there any suggestions on how to achieve both reactive API's and auditing?


回答1:


  1. Spring provided simple Auditing via @EnableR2dbcAuditing, check my example.

  2. Mix JPA in a reactive application is also possible, I have an example to demo run JPA in a reactive application, but not added r2dbc in it.

  3. For your plan, a better solution is applying the cqrs pattern on the database topology, use database cluster for your application.

    • JPA for applying changes, use the main/master database to accept the modification, and sync changes to the secondary/slave database.
    • r2dbc for queries as you expected, use the secondary/slave database to query.
    • use a gateway at the front for the query and command service.

Update: I have created a sample to demo JPA and R2dbc coexistence in a single webflux application. But I do not suggest using it in real-world applications. Consider the 3rd solution above if you really need it.



来源:https://stackoverflow.com/questions/62253297/is-it-possible-to-use-both-spring-data-r2dbc-and-spring-data-jpa-in-a-single-spr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!