From 8f59051a62f00d503ca3f8cc8e7dbdde2f3d665f Mon Sep 17 00:00:00 2001 From: YunaiV Date: Mon, 13 May 2019 23:38:25 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E5=90=8E=E7=AB=AF=EF=BC=9A=E8=B0=83?= =?UTF-8?q?=E6=95=B4=20product=20=E9=A1=B9=E7=9B=AE=EF=BC=8C=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E5=BC=80=E5=8F=91=E4=B8=8D=E5=BC=80=E5=90=AF=E6=96=87?= =?UTF-8?q?=E6=A1=A3=20-=20=E5=90=8E=E7=AB=AF=EF=BC=9Aproduct=20=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=EF=BC=8C=E5=BC=95=E5=85=A5=20seata=20=E5=88=86?= =?UTF-8?q?=E5=B8=83=E5=BC=8F=E4=BA=8B=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +- .../src/main/resources/application-test.yaml | 6 ++ .../src/main/resources/application.yaml | 5 +- product/product-service-impl/pom.xml | 9 +++ .../product/config/DatabaseConfiguration.java | 38 +++++++++- .../main/resources/config/application.yaml | 4 ++ .../src/main/resources/file.conf | 69 +++++++++++++++++++ .../src/main/resources/registry.conf | 14 ++++ 8 files changed, 141 insertions(+), 8 deletions(-) create mode 100644 product/product-application/src/main/resources/application-test.yaml create mode 100644 product/product-service-impl/src/main/resources/file.conf create mode 100644 product/product-service-impl/src/main/resources/registry.conf diff --git a/README.md b/README.md index 3ef8c0f04..98d7b9d75 100644 --- a/README.md +++ b/README.md @@ -80,8 +80,8 @@ TODO 此处应有一个架构图的装逼 JPG 图。 | `admin-web` | 【前端】管理后台 | HTTP 8080 | | | `mobile-web` | 【前端】商城 H5 | HTTP 8000 | | | `admin-application` | 管理员 HTTP 服务 | HTTP 18083 | [接口文档](http://api.shop.iocoder.cn:18099/admin-api/doc.html) | -| `user-application` | 用户 HTTP 服务 | HTTP 18082 |[接口文档](http://api.shop.iocoder.cn:18099/user-api/doc.html) | -| `product-application` | 商品 HTTP 服务 | HTTP 18081 | | +| `user-application` | 用户 HTTP 服务 | HTTP 18082 | [接口文档](http://api.shop.iocoder.cn:18099/user-api/doc.html) | +| `product-application` | 商品 HTTP 服务 | HTTP 18081 | [接口文档](http://api.shop.iocoder.cn:18099/product-api/doc.html) | | `pay-application` | 支付 HTTP 服务 | HTTP 18084 | | | `promotion-application` | 促销 HTTP 服务 | HTTP 18085 | | | `search-application` | 搜索 HTTP 服务 | HTTP 18086 | | diff --git a/product/product-application/src/main/resources/application-test.yaml b/product/product-application/src/main/resources/application-test.yaml new file mode 100644 index 000000000..22be4ba61 --- /dev/null +++ b/product/product-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.product.application.controller diff --git a/product/product-application/src/main/resources/application.yaml b/product/product-application/src/main/resources/application.yaml index 4718d8c3e..67a4b43dd 100644 --- a/product/product-application/src/main/resources/application.yaml +++ b/product/product-application/src/main/resources/application.yaml @@ -9,7 +9,4 @@ server: context-path: /product-api/ swagger: - title: 商品子系统 - description: 商品子系统 - version: 1.0.0 - base-package: cn.iocoder.mall.product.application.controller + enable: false diff --git a/product/product-service-impl/pom.xml b/product/product-service-impl/pom.xml index 95498304c..961cd349f 100644 --- a/product/product-service-impl/pom.xml +++ b/product/product-service-impl/pom.xml @@ -44,6 +44,15 @@ mybatis-plus-boot-starter + + io.seata + seata-spring + + + io.seata + seata-dubbo + + org.apache.dubbo diff --git a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/config/DatabaseConfiguration.java b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/config/DatabaseConfiguration.java index b1020e51a..1532adc63 100644 --- a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/config/DatabaseConfiguration.java +++ b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/config/DatabaseConfiguration.java @@ -1,14 +1,48 @@ package cn.iocoder.mall.product.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.Value; +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; +import javax.sql.DataSource; + @Configuration @MapperScan("cn.iocoder.mall.product.dao") // 扫描对应的 Mapper 接口 @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; -} \ No newline at end of file + @Bean("druidDataSource") + @ConfigurationProperties("spring.datasource.druid") + public DruidDataSource druidDataSource(){ + return DruidDataSourceBuilder.create().build(); + } + + @ConfigurationProperties(prefix = "spring.datasource") + @Primary + @Bean("dataSource") + @DependsOn("druidDataSource") // 解决多数据源,循环依赖的问题。主要发生点在 DataSourceInitializerInvoker + public DataSource dataSource() { + DruidDataSource druidDataSource = druidDataSource(); + return new DataSourceProxy(druidDataSource); + } + + @Bean + public GlobalTransactionScanner globalTransactionScanner() { + return new GlobalTransactionScanner(applicationId, txServiceGroup); + } + +} diff --git a/product/product-service-impl/src/main/resources/config/application.yaml b/product/product-service-impl/src/main/resources/config/application.yaml index a7d3cee8d..e4814b7bd 100644 --- a/product/product-service-impl/src/main/resources/config/application.yaml +++ b/product/product-service-impl/src/main/resources/config/application.yaml @@ -39,3 +39,7 @@ rocketmq: name-server: 127.0.0.1:9876 producer: group: product-producer-group + +# seata +seata: + tx-service-group: my_test_tx_group diff --git a/product/product-service-impl/src/main/resources/file.conf b/product/product-service-impl/src/main/resources/file.conf new file mode 100644 index 000000000..8b60b29c3 --- /dev/null +++ b/product/product-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/product/product-service-impl/src/main/resources/registry.conf b/product/product-service-impl/src/main/resources/registry.conf new file mode 100644 index 000000000..f73989514 --- /dev/null +++ b/product/product-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 + } +}