java - jooQ spring boot Multiple Schema(Read Write Split) -
i want use jooq spring boot. have master slave architecture, want use jooq master slave architecture (master write & slave read).
how should proceed. using pom.xml configure jooq
<configuration> <jdbc> <driver>com.mysql.jdbc.driver</driver> <url>${datasource.primary.url}</url> <user>${datasource.primary.username}</user> <password>${datasource.primary.password}</password> </jdbc> <generator> <name>org.jooq.util.defaultgenerator</name> <database> <name>org.jooq.util.mysql.mysqldatabase</name> <includes>.*</includes> <excludes/> <inputschema>jpa</inputschema> </database> <generate> <deprecated>false</deprecated> </generate> <target> <packagename>com.gensrc.model</packagename> <directory>src/main/java</directory> </target> </generator> </configuration>
and autowiring dslcontext
but how change code now.
from comments:
i want route write queries master & read queries slave.
i'm not sure hard distinction between write=master, read=slave idea. sometimes, need read master within same transaction boundaries (i.e. read uncommitted data), in case of sending read query slave yield wrong results.
so, best place implement routing have separate datasource
instances , inject them jooq accordingly. you'll separating master , slave in service layer explicitly, transparently jooq.
you could, of course, implement original requirement using jooq executelistener
, providing jooq right jdbc connection
depending on query type (executecontext.type()
), again, think break quite soon.
Comments
Post a Comment