Spring Data R2DBC master slave configuration - spring

Is there a way in Spring Data R2DBC to setup a second datasource as slave read-only ?

It is easy to configure multi R2dbc connections in the same application.
Check my example project: https://github.com/hantsy/spring-puzzles/blob/master/multi-r2dbc-connectionfactorie

Related

Does Spring Boot supports Master Slave config of RDBMS DB

I have a multiple Spring Boot based Micro services which connect a DB2 data base (Master BD). We want to have same replica of Master DB which is called Slave DB2 DB. Every month we have some maintenance on master DB for 5-10 hrs during this time we want all our apps to automatically connect to Slave DB after this time period apps should switch back to Master without manual intervention.
Is this possible to achieve in Sprint Boot. I thought of using Spring Cloud Hystrix but is it correct architectural pattern. Any other better approach.
It's possible to do this on the infrastructure level, your apps does not need to know that there was a failover.
If you want to solve this on the application side, you can use Spring Cloud Circuitbreaker (Hystrix is deprecated, but you can use it with Resilience4J).

How to use Spring transactions with plain old jdbc connection without Spring jdbc template?

We have an old EJB based web application which we are supposed to migrate into Spring boot. For database connectivity, it is a plain old jdbc connection approach as of now.
We want to use Spring transactions and remove EJB transactions but willing to keep plain old jdbc connectivity same. In short we don't want to make changes in our DAO layer to convert plain old jdbc to Spring JdbcTemplate.
Please note that we have our own connection pooling algorithm and we create connection object and close it in the pool.
Along with this we want our application to be multi-tenant that can work with multiple databases on the basis of 'tenantID' that we will provide.
I actually tried to implement this but it is not working. I had to manually do con.commit(); and con.rollback();
Is there any way to use Spring transactions with plain old jdbc connectivity with above scenario?

Redis Spring write to master , read from slave , no sentinel

I want have a setup of redis where I write to master and read from slave, without any sentinel.
I can see spring does have an article for above here :
https://docs.spring.io/spring-data/redis/docs/2.2.0.M1/reference/html/#redis:write-to-master-read-from-replica
I am using #Cacheable annotation for caching, where do I specify that read should happen from master and write from slave?
The write-to-master/read-from-slave is implemented in the lettuce redis client. It is transparent to your application code

Spring Boot (Spring Data JPA) - configure PostgreSQL Read Replicas

What is the simplest way to configure read replicas with Spring Boot and Spring Data JPA? I'm searching a lot and cannot find solution.
AWS RDS Aurora Postgresql gives 2 endpoints:
master (write)
replicas (read)
I want to configure my application to use this endpoints.
Why do you need to configure the read replica with Spring Boot, I am guessing that you just need to connect with the read replica, right?
Have you looked the aws sdk for java?
You need to look over a class there named DescribeDBClusterEndpointsResult.

Resuming Spring Data JPA connection after database is restarted

I am using Spring Boot with Spring Data JPA to query database through Repository. If the backend database is booted for some reason, then Spring Boot cannot connect to that database again unless rebooted. Is there a way to get the Data JPA to repopulate connections to database after DB reboot?
In Spring Boot, we can solve this problem adding these configurations in the application.properties file:
spring.datasource.testWhileIdle = true
spring.datasource.timeBetweenEvictionRunsMillis = 60000
spring.datasource.validationQuery = SELECT 1
Checkout the full explanation here

Resources