GreekPanda commented on issue #14238:
URL: 
https://github.com/apache/shardingsphere/issues/14238#issuecomment-1000618398


   > @GreekPanda Hi, can you provider a demo project?
   
   @zjcnb Hi, I'm so sorry that I can't provide a demo project which it's 
deeply depent on my own company spring cloud frame, I've tried to remove code 
from it, but it's a huge tough work. Is there any demos on spring cloud that I 
can reference? 
   By the way, I wrote a configure file in resource directory and customized 
data source, it worked.
   Here is my configure file:
   
   @SpringBootApplication(exclude = {
                DataSourceAutoConfiguration.class,
                DataSourceTransactionManagerAutoConfiguration.class,
                DruidDataSourceAutoConfigure.class ,
                HibernateJpaAutoConfiguration.class})
   @EnableDiscoveryClient
   @EnableFeignClients
   @EnableZhqcSwagger
   @EnableZhqcDozer
   @EnableZhqcRedis
   @MapperScan("com.zhqc.**.dao")
   @ComponentScan({"com.zhqc"})
   public class ShardingSeataApplication {
        public static void main(String[] args) {
                SpringApplication.run(ShardingSeataApplication.class, args);
   
        }
        @SneakyThrows
        @Bean
        public DataSource dataSource() {
                DataSource dataSource =  YamlShardingSphereDataSourceFactory.
                                
createDataSource(ResourceUtils.getFile("D:\\study\\shardingsphere\\demo\\bywl-shardingsphere-seata-demo\\src\\main\\resources\\config-sharding.yaml"));
                return dataSource;
        }
   }
   
   
   config-sharding.yaml: 
   
   dataSources:
     write_ds_0:
       dataSourceClassName: com.zaxxer.hikari.HikariDataSource
       driver-class-name: com.mysql.cj.jdbc.Driver
       jdbcUrl: 
jdbc:mysql://172.17.30.210:3306/write_ds_0?serverTimezone=UTC&useSSL=false
       username: root
       password: 123456!
   
     write_ds_1:
       dataSourceClassName: com.zaxxer.hikari.HikariDataSource
       driver-class-name: com.mysql.cj.jdbc.Driver
       jdbcUrl: 
jdbc:mysql://172.17.30.210:3306/write_ds_1?serverTimezone=UTC&useSSL=false
       username: root
       password: 123456!!
   
   
     read_ds_0:
       dataSourceClassName: com.zaxxer.hikari.HikariDataSource
       driver-class-name: com.mysql.cj.jdbc.Driver
       jdbcUrl: 
jdbc:mysql://172.17.30.210:3306/read_ds_0?serverTimezone=UTC&useSSL=false
       username: root
       password: 123456!
   
   
     read_ds_1:
       dataSourceClassName: com.zaxxer.hikari.HikariDataSource
       driver-class-name: com.mysql.cj.jdbc.Driver
       jdbcUrl: 
jdbc:mysql://172.17.30.210:3306/read_ds_1?serverTimezone=UTC&useSSL=false
       username: root
       password: 123456!
   
   rules:
   - !READWRITE_SPLITTING
     dataSources:
       pr_ds:
         writeDataSourceName: write_ds_0, write_ds_1
         readDataSourceNames:
           - read_ds_0
           - read_ds_1
   
   - !SHARDING
     tables:
       t_order:
         actualDataNodes: write_ds_${0..1}.t_order_${0..1}
         tableStrategy:
           standard:
             shardingColumn: order_id
             shardingAlgorithmName: t_order_inline
         keyGenerateStrategy:
           column: order_id
           keyGeneratorName: snowflake
       t_order_item:
         actualDataNodes: write_ds_${0..1}.t_order_item_${0..1}
         tableStrategy:
           standard:
             shardingColumn: order_id
             shardingAlgorithmName: t_order_item_inline
         keyGenerateStrategy:
           column: order_item_id
           keyGeneratorName: snowflake
     bindingTables:
       - t_order,t_order_item
     broadcastTables:
       - t_address, t_order_rules
     defaultDatabaseStrategy:
       standard:
         shardingColumn: order_id
         shardingAlgorithmName: database_inline
     defaultTableStrategy:
       none:
     
     shardingAlgorithms:
       database_inline:
           type: INLINE
           props:
             algorithm-expression: write_ds_${order_id % 2}
       t_order_inline:
         type: INLINE
         props:
           algorithm-expression: t_order_${order_id % 2}
       t_order_item_inline:
         type: INLINE
         props:
           algorithm-expression: t_order_item_${order_id % 2}
     
     keyGenerators:
       snowflake:
         type: SNOWFLAKE
         props:
             worker-id: 123
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to