问题
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:
Spring provided simple Auditing via
@EnableR2dbcAuditing
, check my example.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.
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