Best practices on configuring 2 DataSource with Jooq

Viewed 449

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. Writer is default dslContext provided by SpringBoot auto-configure.
  • Reader dslContext 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.

  1. Is there any best practice for configuring 2 or more dslContext?
  2. 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?
0 Answers
Related