Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use JDBC and R2DBC alongside each other in the same Spring application?

Tags:

spring

jdbc

r2dbc

I have been working on a spring application for some time now and it has been using JDBC to retrieve data from my Postgres database server.

Now my application has progressed to the point that it requires some reactive system to it. In my case, I am trying to emit user interaction (mainly notifications) as a stream to my REST service and this requires a non-blocking functionality that is not provided by JDBC but by R2DBC.

My question is, is it possible to use both R2DBC and JDBC together in the same application? I only need to stream notifications and the rest is perfectly fine using JDBC.

like image 545
eyoeldefare Avatar asked Sep 05 '25 03:09

eyoeldefare


1 Answers

It is possible to use both JDBC and R2DBC in a single application. There is nothing in either specification that prevents this, and it is unlikely that there is anything in an implementation of either specification that would interfere with an implementation of the other specification.

That said, performing blocking calls like JDBC inside reactive code is not advisable. But there is no problem using both in a single application itself, as long as they aren't mixed together in some way, as you will need to guard against accidentally calling code that blocks (eg by calling JDBC) from your reactive code.

like image 115
Mark Rotteveel Avatar answered Sep 07 '25 23:09

Mark Rotteveel