Skip to content

Commit

Permalink
feat($ShardingSphere): support read-write load balancer for database
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
johnnymillergh committed Apr 2, 2022
1 parent 5ba4a42 commit 3ef9765
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,33 +50,21 @@ spring:
# The default is 0. We set it as 0 too.
file-size-threshold: 0
shardingsphere:
props:
sql-show: true
datasource:
master0:
name: master0
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/muscle_and_fitness_00?useSSL=true&useUnicode=true
username: maf_mysql_rw
password: maf@mysql
master1:
name: master1
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/muscle_and_fitness_01?useSSL=true&useUnicode=true
url: jdbc:mysql://localhost:3306/muscle_and_fitness?useSSL=true&useUnicode=true
username: maf_mysql_rw
password: maf@mysql
slave0:
name: slave0
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3307/muscle_and_fitness_00?useSSL=true&useUnicode=true
username: maf_mysql_r
password: maf@mysql
slave1:
name: slave1
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3307/muscle_and_fitness_01?useSSL=true&useUnicode=true
url: jdbc:mysql://localhost:3307/muscle_and_fitness?useSSL=true&useUnicode=true
username: maf_mysql_r
password: maf@mysql
quartz:
Expand All @@ -86,31 +74,19 @@ spring:
url: jdbc:mysql://localhost:3306/QUARTZ_DB?useSSL=true&useUnicode=true
username: maf_mysql_rw
password: maf@mysql
names: master0,slave0,master1,slave1,quartz
sharding:
master-slave-rules:
master0:
slave-data-source-names: slave0
master-data-source-name: master0
master1:
slave-data-source-names: slave1
master-data-source-name: master1
default-database-strategy:
inline:
algorithm-expression: master$->{id % 2}
sharding-column: id
tables:
user:
table-strategy:
inline:
sharding-column: id
algorithm-expression: "user_$->{String.format(\"%04d\", new BigDecimal(id).abs().divideAndRemainder(2)[1].longValue())}"
key-generator:
column: id
type: SNOWFLAKE
actual-data-nodes: "master$->{0..1}.user_$->{(0..1).collect{String.format(\"%04d\", it)}}"
props:
sql-show: true
names: master0,slave0,quartz
rules:
readwrite-splitting:
data-sources:
readwrite-data-sources:
type: Static
props:
write-data-source-name: master0
read-data-source-names: slave0
load-balancer-name: readwrite-load-balancer
load-balancers:
readwrite-load-balancer:
type: ROUND_ROBIN

logging:
config: classpath:logback-configuration/logback-${spring.profiles.active}.xml
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
@Slf4j
@Configuration
@EnableTransactionManagement
//@Import({
// DataSourceConfiguration.class
//})
@ConditionalOnClass({MybatisPlusAutoConfiguration.class})
@MapperScan("com.jmsoftware.maf.springcloudstarter.*.repository")
public class MyBatisPlusConfiguration {
Expand Down

0 comments on commit 3ef9765

Please sign in to comment.