diff --git a/order/order-application/src/main/resources/application-test.yaml b/order/order-application/src/main/resources/application-test.yaml new file mode 100644 index 00000000..ff9f80fd --- /dev/null +++ b/order/order-application/src/main/resources/application-test.yaml @@ -0,0 +1,6 @@ +swagger: + enable: true + title: 订单子系统 + description: 订单子系统 + version: 1.0.0 + base-package: cn.iocoder.mall.pay.application.controller diff --git a/order/order-application/src/main/resources/application.yaml b/order/order-application/src/main/resources/application.yaml index e9f9b609..da833636 100644 --- a/order/order-application/src/main/resources/application.yaml +++ b/order/order-application/src/main/resources/application.yaml @@ -9,7 +9,4 @@ server: context-path: /order-api/ swagger: - title: 订单子系统 - description: 订单子系统 - version: 1.0.0 - base-package: cn.iocoder.mall.pay.application.controller + enable: false diff --git a/order/order-application/src/main/resources/mybatis-config.xml b/order/order-application/src/main/resources/mybatis-config.xml deleted file mode 100644 index 7f604cc7..00000000 --- a/order/order-application/src/main/resources/mybatis-config.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/config/DatabaseConfiguration.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/config/DatabaseConfiguration.java index e0da6e15..ad7a667a 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/config/DatabaseConfiguration.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/config/DatabaseConfiguration.java @@ -1,15 +1,15 @@ package cn.iocoder.mall.order.biz.config; import com.alibaba.druid.pool.DruidDataSource; +import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder; import io.seata.rm.datasource.DataSourceProxy; import io.seata.spring.annotation.GlobalTransactionScanner; import org.mybatis.spring.annotation.MapperScan; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.DependsOn; import org.springframework.context.annotation.Primary; import org.springframework.transaction.annotation.EnableTransactionManagement; @@ -20,56 +20,29 @@ import javax.sql.DataSource; @EnableTransactionManagement(proxyTargetClass = true) // 启动事务管理。为什么使用 proxyTargetClass 参数,参见 https://blog.csdn.net/huang_550/article/details/76492600 public class DatabaseConfiguration { - // 数据源,使用 HikariCP - @Value("${spring.application.name}") private String applicationId; + @Value("${seata.tx-service-group}") + private String txServiceGroup; - @Autowired - private DataSourceProperties dataSourceProperties; - - @Bean -// @Primary + @Bean("druidDataSource") + @ConfigurationProperties("spring.datasource.druid") public DruidDataSource druidDataSource(){ - DruidDataSource druidDataSource = new DruidDataSource(); - druidDataSource.setUrl(dataSourceProperties.getUrl()); - druidDataSource.setUsername(dataSourceProperties.getUsername()); - druidDataSource.setPassword(dataSourceProperties.getPassword()); - druidDataSource.setDriverClassName(dataSourceProperties.getDriverClassName()); - druidDataSource.setInitialSize(0); - druidDataSource.setMaxActive(180); - druidDataSource.setMaxWait(60000); - druidDataSource.setMinIdle(0); - druidDataSource.setValidationQuery("Select 1 from DUAL"); - druidDataSource.setTestOnBorrow(false); - druidDataSource.setTestOnReturn(false); - druidDataSource.setTestWhileIdle(true); - druidDataSource.setTimeBetweenEvictionRunsMillis(60000); - druidDataSource.setMinEvictableIdleTimeMillis(25200000); - druidDataSource.setRemoveAbandoned(true); - druidDataSource.setRemoveAbandonedTimeout(1800); - druidDataSource.setLogAbandoned(true); - return druidDataSource; + return DruidDataSourceBuilder.create().build(); } @ConfigurationProperties(prefix = "spring.datasource") @Primary @Bean("dataSource") -// @Bean - public DataSource dataSource(DruidDataSource dataSource) { - return new DataSourceProxy(dataSource); + @DependsOn("druidDataSource") // 解决多数据源,循环依赖的问题。主要发生点在 DataSourceInitializerInvoker + public DataSource dataSource() { + DruidDataSource druidDataSource = druidDataSource(); + return new DataSourceProxy(druidDataSource); } - /** - * 注册一个StatViewServlet - * - * @return global transaction scanner - */ @Bean public GlobalTransactionScanner globalTransactionScanner() { - return new GlobalTransactionScanner(applicationId, "my_test_tx_group"); - // TODO 芋艿,txServiceGroup 后续要编辑下 + return new GlobalTransactionScanner(applicationId, txServiceGroup); } - } diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/config/SeataConfiguration.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/config/SeataConfiguration.java deleted file mode 100644 index ace05c0c..00000000 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/config/SeataConfiguration.java +++ /dev/null @@ -1,9 +0,0 @@ -package cn.iocoder.mall.order.biz.config; - -import org.springframework.context.annotation.Configuration; - -@Configuration -public class SeataConfiguration { - - -} diff --git a/order/order-service-impl/src/main/resources/config/application.yaml b/order/order-service-impl/src/main/resources/config/application.yaml index 6cb9ee36..a60232b1 100644 --- a/order/order-service-impl/src/main/resources/config/application.yaml +++ b/order/order-service-impl/src/main/resources/config/application.yaml @@ -59,3 +59,7 @@ logging: level: # dao 开启 debug 模式 mybatis 输入 sql cn.iocoder.mall.order.biz.dao: debug + +# seata +seata: + tx-service-group: my_test_tx_group diff --git a/order/order-service-impl/src/main/resources/file.conf b/order/order-service-impl/src/main/resources/file.conf new file mode 100644 index 00000000..8b60b29c --- /dev/null +++ b/order/order-service-impl/src/main/resources/file.conf @@ -0,0 +1,69 @@ +transport { + # tcp udt unix-domain-socket + type = "TCP" + #NIO NATIVE + server = "NIO" + #enable heartbeat + heartbeat = true + #thread factory for netty + thread-factory { + boss-thread-prefix = "NettyBoss" + worker-thread-prefix = "NettyServerNIOWorker" + server-executor-thread-prefix = "NettyServerBizHandler" + share-boss-worker = false + client-selector-thread-prefix = "NettyClientSelector" + client-selector-thread-size = 1 + client-worker-thread-prefix = "NettyClientWorkerThread" + # netty boss thread size,will not be used for UDT + boss-thread-size = 1 + #auto default pin or 8 + worker-thread-size = 8 + } +} + +service { + #vgroup->rgroup + vgroup_mapping.my_test_tx_group = "default" + #only support single node + default.grouplist = "180.167.213.26:8091" + #degrade current not support + enableDegrade = false + #disable + disable = false +} + +client { + async.commit.buffer.limit = 10000 + lock { + retry.internal = 10 + retry.times = 30 + } +} +## transaction log store +store { + ## store mode: file、db + mode = "file" + + ## file store + file { + dir = "file_store/data" + + # branch session size , if exceeded first try compress lockkey, still exceeded throws exceptions + max-branch-session-size = 16384 + # globe session size , if exceeded throws exceptions + max-global-session-size = 512 + # file buffer size , if exceeded allocate new buffer + file-write-buffer-cache-size = 16384 + # when recover batch read size + session.reload.read_size = 100 + } + + ## database store + db { + driver_class = "" + url = "" + user = "" + password = "" + } +} + diff --git a/order/order-service-impl/src/main/resources/registry.conf b/order/order-service-impl/src/main/resources/registry.conf new file mode 100644 index 00000000..f7398951 --- /dev/null +++ b/order/order-service-impl/src/main/resources/registry.conf @@ -0,0 +1,14 @@ +registry { + type = "file" + + file { + name = "file.conf" + } + + zk { + cluster = "default" + serverAddr = "192.168.88.10:2181" + session.timeout = 6000 + connect.timeout = 2000 + } +}