We are splitting read and write side of our DB queries. Achieved that as mentioned jooQ spring boot Multiple Schema(Read Write Split)
Our config:
- We are using 2
dslContext.Writeris default dslContext provided by SpringBoot auto-configure. ReaderdslContext we are creating via deriving existing configuration of default context with different DataSource.
public DSLContext getReaderContext(@Qualifier("readerDataSource") DataSource readerDataSource, DSLContext dslContext) {
return DSL.using(dslContext.configuration().derive(readerDataSource));
}
So Reader context is using same instance of ExecuteListener, TransactionListener, Settings in the configuration. This is to reduce manual configuration.
Other configuration that we tried:
public DSLContext getReaderContext(@Qualifier("readerDataSource") DataSource readerDataSource, JooqProperties jooqProperties, Settings settings) {
return DSL.using(readerDataSource, jooqProperties.determineSqlDialect(readerDataSource), settings)
}
Here all configuration instance is different. But manual work is there. Like there is no ExecuteListener(Default JooqExceptionTranslator) in reader context, so if required we have to add manual configuration.
- Is there any best practice for configuring 2 or more dslContext?
- Also our reader datasource can't execute transaction (AWS Read Replica), as we are using same config as writer, is it ok to have SpringTransactionProvider for reader?