Browse Source

sharding 5.1.0

master
tangmingyou 4 years ago
parent
commit
4b031b606b
  1. 11
      im-das/im-das-user/pom.xml
  2. 32
      im-das/im-das-user/src/main/resources/application.properties
  3. 1
      im-das/im-das-user/src/main/resources/application.yml
  4. 4
      im-das/im-das-user/src/test/java/nets/sopod/soim/das/user/test/DasUserApplicationTest.java
  5. 12
      pom.xml

11
im-das/im-das-user/pom.xml

@ -57,17 +57,10 @@
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
<version>${shardingsphere.version}</version>
</dependency>
<!-- <dependency>
<!--<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>sharding-jdbc-spring-boot-starter-infra</artifactId>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
<artifactId>shardingsphere-sharding-spring-boot-starter</artifactId>
</dependency>-->
<dependency>
<groupId>mysql</groupId>

32
im-das/im-das-user/src/main/resources/application.properties

@ -2,19 +2,27 @@ spring.profiles.active=${SPRING_PROFILES_ACTIVE:dev}
# sharding-jdbc 配置
# 配置数据源
spring.shardingsphere.datasource.names=db1
spring.shardingsphere.datasource.db1.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.db1.driver-class-name=com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.db1.jdbc-url=jdbc:mysql://cd-cdb-mrz9fw80.sql.tencentcdb.com:61843/soim_db?serverTimezone=GMT%2B8
spring.shardingsphere.datasource.db1.username=root
spring.shardingsphere.datasource.db1.password=sopod@2347#
spring.shardingsphere.datasource.names=ds1
spring.shardingsphere.datasource.ds1.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.ds1.driver-class-name=com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.ds1.jdbc-url=jdbc:mysql://cd-cdb-mrz9fw80.sql.tencentcdb.com:61843/soim_db?serverTimezone=GMT%2B8
spring.shardingsphere.datasource.ds1.username=root
spring.shardingsphere.datasource.ds1.password=sopod@2347#
# 分表
spring.shardingsphere.sharding.tables.im_user.actual-data-nodes=db1.im_user_$->{0..2}
# 指定t_user表的分片策略,分片策略包括分片键和分片算法
spring.shardingsphere.sharding.tables.im_user.table-strategy.inline.sharding-column=id
spring.shardingsphere.sharding.tables.im_user.table-strategy.inline.algorithm-expression=im_user_$->{id % 3}
#spring.shardingsphere.sharding.tables.im_user.actual-data-nodes=db1.im_user_$->{0..2}
## 指定im_user表的分片策略,分片策略包括分片键和分片算法
#spring.shardingsphere.sharding.tables.im_user.table-strategy.inline.sharding-column=id
#spring.shardingsphere.sharding.tables.im_user.table-strategy.inline.algorithm-expression=im_user_$->{id % 3}
# 5.1.0 分表
# https://github.com/apache/shardingsphere/blob/master/examples/shardingsphere-jdbc-example/single-feature-example/sharding-example/sharding-raw-jdbc-example/src/main/resources/META-INF/sharding-tables.yaml
spring.shardingsphere.rules.sharding.tables.im_user.actual-data-nodes=ds1.im_user_$->{0..2}
spring.shardingsphere.rules.sharding.tables.im_user.table-strategy.standard.sharding-column=id
spring.shardingsphere.rules.sharding.tables.im_user.table-strategy.standard.sharding-algorithm-name=im-user-inline
spring.shardingsphere.rules.sharding.binding-tables=im_user
spring.shardingsphere.rules.sharding.sharding-algorithms.im-user-inline.type=INLINE
spring.shardingsphere.rules.sharding.sharding-algorithms.im-user-inline.props.algorithm-expression=im_user_$->{id % 3}
# 打开sharding-jdbc sql输出日志
spring.shardingsphere.props.sql.show=true
spring.shardingsphere.props.sql-show=true

1
im-das/im-das-user/src/main/resources/application.yml

@ -8,3 +8,4 @@ dubbo:
mybatis-plus:
mapper-locations: classpath:mapper/*.xml

4
im-das/im-das-user/src/test/java/nets/sopod/soim/das/user/test/DasUserApplicationTest.java

@ -26,8 +26,8 @@ public class DasUserApplicationTest {
@Test
public void test() {
ImUser user1 = new ImUser()
.setId(1L)
.setUsername("野孩子")
.setId(4L)
.setUsername("野孩子2")
.setPassword("123456")
.setPhone("17882451908")
.setCreateTime(ImClock.date());

12
pom.xml

@ -37,7 +37,7 @@
<spring.version>5.1.9.RELEASE</spring.version>
<dubbo.version>3.0.5</dubbo.version>
<curator5_version>4.2.0</curator5_version>
<shardingsphere.version>5.0.1</shardingsphere.version>
<shardingsphere.version>5.1.0</shardingsphere.version>
</properties>
<dependencyManagement>
@ -157,16 +157,16 @@
<artifactId>HikariCP</artifactId>
<version>5.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-sharding-spring-boot-starter</artifactId>
<version>${shardingsphere.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
<version>${shardingsphere.version}</version>
</dependency>
<!-- <dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency>-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>

Loading…
Cancel
Save