From 60db9b9a77dfa4d24c3d9efa9777481b19d146da Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 12 Apr 2020 20:30:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=20order=20=E6=A8=A1=E5=9D=97=E6=8E=A5?= =?UTF-8?q?=E5=85=A5=20SCA=20Dubbo=20=E5=92=8C=20Nacos=20Discovery=20?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=EF=BC=8C=E5=90=8C=E6=97=B6=E5=B0=86=20Seata?= =?UTF-8?q?=20=E4=BF=AE=E6=94=B9=E6=88=90=20SCA=20Seata=20=E7=BB=84?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/common-dependencies/pom.xml | 10 +++ .../src/main/resources/application-test.yaml | 6 -- order/order-service-impl/pom.xml | 39 +++++------ .../biz/config/DatabaseConfiguration.java | 36 ---------- .../biz/service/OrderReturnServiceImpl.java | 4 +- .../resources/config/application-test.yaml | 7 -- .../main/resources/config/application.yaml | 41 ++++++----- .../src/main/resources/file.conf | 69 ------------------- .../src/main/resources/registry.conf | 14 ---- order/pom.xml | 13 ++++ .../main/resources/config/application.yaml | 2 + 11 files changed, 68 insertions(+), 173 deletions(-) delete mode 100644 order/order-application/src/main/resources/application-test.yaml delete mode 100644 order/order-service-impl/src/main/resources/config/application-test.yaml delete mode 100644 order/order-service-impl/src/main/resources/file.conf delete mode 100644 order/order-service-impl/src/main/resources/registry.conf diff --git a/common/common-dependencies/pom.xml b/common/common-dependencies/pom.xml index dd577d92a..8846d9e3b 100644 --- a/common/common-dependencies/pom.xml +++ b/common/common-dependencies/pom.xml @@ -22,6 +22,8 @@ 2.2.0.RELEASE 2.7.1 + + 1.1.0 @@ -56,6 +58,14 @@ dubbo ${dubbo.version} + + + + io.seata + seata-spring-boot-starter + ${seata.version} + + diff --git a/order/order-application/src/main/resources/application-test.yaml b/order/order-application/src/main/resources/application-test.yaml deleted file mode 100644 index ff9f80fd8..000000000 --- a/order/order-application/src/main/resources/application-test.yaml +++ /dev/null @@ -1,6 +0,0 @@ -swagger: - enable: true - title: 订单子系统 - description: 订单子系统 - version: 1.0.0 - base-package: cn.iocoder.mall.pay.application.controller diff --git a/order/order-service-impl/pom.xml b/order/order-service-impl/pom.xml index 5b16357e1..29b423cda 100644 --- a/order/order-service-impl/pom.xml +++ b/order/order-service-impl/pom.xml @@ -76,23 +76,26 @@ mybatis-plus-boot-starter - - io.seata - seata-spring - - - io.seata - seata-dubbo - - - org.apache.dubbo - dubbo + com.alibaba.cloud + spring-cloud-starter-dubbo + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + + com.alibaba.cloud + spring-cloud-alibaba-seata - org.apache.dubbo - dubbo-spring-boot-starter + io.seata + seata-spring-boot-starter @@ -107,16 +110,6 @@ xxl-job-core - - - org.apache.curator - curator-framework - - - org.apache.curator - curator-recipes - - com.google.guava 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 ad7a667ab..22c0fbcf6 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,48 +1,12 @@ 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.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.order.biz.dao") // 扫描对应的 Mapper 接口 @EnableTransactionManagement(proxyTargetClass = true) // 启动事务管理。为什么使用 proxyTargetClass 参数,参见 https://blog.csdn.net/huang_550/article/details/76492600 public class DatabaseConfiguration { - @Value("${spring.application.name}") - private String applicationId; - @Value("${seata.tx-service-group}") - private String txServiceGroup; - - @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/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/OrderReturnServiceImpl.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/OrderReturnServiceImpl.java index eba36ab9b..2505ea60b 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/OrderReturnServiceImpl.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/OrderReturnServiceImpl.java @@ -49,9 +49,9 @@ public class OrderReturnServiceImpl implements OrderReturnService { private OrderItemMapper orderItemMapper; @Autowired private OrderReturnMapper orderReturnMapper; - - @Reference(validation = "true") + @Autowired private OrderLogisticsService orderLogisticsService; + @Reference(validation = "true", version = "${dubbo.consumer.PayRefundService.version}") private PayRefundService payRefundService; @Reference(validation = "true", version = "${dubbo.consumer.DataDictService.version}") diff --git a/order/order-service-impl/src/main/resources/config/application-test.yaml b/order/order-service-impl/src/main/resources/config/application-test.yaml deleted file mode 100644 index 268e6407b..000000000 --- a/order/order-service-impl/src/main/resources/config/application-test.yaml +++ /dev/null @@ -1,7 +0,0 @@ -spring: - # datasource - datasource: - url: jdbc:mysql://192.168.88.14:3306/mall_order?useSSL=false&useUnicode=true&characterEncoding=UTF-8 - driver-class-name: com.mysql.jdbc.Driver - username: root - password: ${MALL_MYSQL_PASSWORD} 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 68a6725b3..84b16eae2 100644 --- a/order/order-service-impl/src/main/resources/config/application.yaml +++ b/order/order-service-impl/src/main/resources/config/application.yaml @@ -5,15 +5,14 @@ spring: driver-class-name: com.mysql.jdbc.Driver username: root password: ${MALL_MYSQL_PASSWORD} - application: - name: order-impl # 设置值保证程序启动时不报错,具体的值需要修改[nengjie] -# mybatis -#mybatis: -# config-location: classpath:mybatis-config.xml -# mapper-locations: classpath:mapper/*.xml -# type-aliases-package: cn.iocoder.mall.order.biz.dataobject -# + # Spring Cloud 配置项 + cloud: + nacos: + # Spring Cloud Nacos Discovery 配置项 + discovery: + server-addr: 127.0.0.1:8848 # Nacos 服务器地址 + # mybatis-plus mybatis-plus: configuration: @@ -24,18 +23,22 @@ mybatis-plus: mapper-locations: classpath*:mapper/*.xml type-aliases-package: cn.iocoder.mall.order.biz.dataobject -# dubbo +# Dubbo 配置项 dubbo: - application: - name: order-service + # Dubbo 注册中心 registry: - address: zookeeper://127.0.0.1:2181 + address: spring-cloud://127.0.0.1:8848 # 指定 Dubbo 服务注册中心的地址 + # Spring Cloud Alibaba Dubbo 专属配置 + cloud: + subscribed-services: admin-application, user-application, product-application, promotion-application, pay-application # 设置订阅的应用列表,默认为 * 订阅所有应用 + # Dubbo 提供者的协议 protocol: - port: -1 name: dubbo + port: -1 + # Dubbo 提供服务的扫描基础包 scan: base-packages: cn.iocoder.mall.order.biz.service - + # Dubbo 服务提供者的配置 provider: filter: -exception CartService: @@ -73,6 +76,12 @@ logging: # dao 开启 debug 模式 mybatis 输入 sql cn.iocoder.mall.order.biz.dao: debug -# seata +# Seata 配置项 seata: - tx-service-group: my_test_tx_group + # Seata 注册中心配置项 + registry: + type: nacos # 注册中心类型 + nacos: + serverAddr: ${spring.cloud.nacos.discovery.server-addr} # Nacos 服务地址 + namespace: # Nacos 命名空间 + cluster: default # 使用的 Seata 分组 diff --git a/order/order-service-impl/src/main/resources/file.conf b/order/order-service-impl/src/main/resources/file.conf deleted file mode 100644 index 8b60b29c3..000000000 --- a/order/order-service-impl/src/main/resources/file.conf +++ /dev/null @@ -1,69 +0,0 @@ -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 deleted file mode 100644 index f73989514..000000000 --- a/order/order-service-impl/src/main/resources/registry.conf +++ /dev/null @@ -1,14 +0,0 @@ -registry { - type = "file" - - file { - name = "file.conf" - } - - zk { - cluster = "default" - serverAddr = "192.168.88.10:2181" - session.timeout = 6000 - connect.timeout = 2000 - } -} diff --git a/order/pom.xml b/order/pom.xml index 48044d83c..116af0d2e 100644 --- a/order/pom.xml +++ b/order/pom.xml @@ -16,4 +16,17 @@ order-service-api order-service-impl + + + + + cn.iocoder.mall + common-dependencies + 1.0-SNAPSHOT + pom + import + + + + diff --git a/pay/pay-service-impl/src/main/resources/config/application.yaml b/pay/pay-service-impl/src/main/resources/config/application.yaml index 78543d4c3..1b5d79598 100644 --- a/pay/pay-service-impl/src/main/resources/config/application.yaml +++ b/pay/pay-service-impl/src/main/resources/config/application.yaml @@ -31,8 +31,10 @@ dubbo: protocol: name: dubbo port: -1 + # Dubbo 提供服务的扫描基础包 scan: base-packages: cn.iocoder.mall.pay.biz.service + # Dubbo 服务提供者的配置 provider: filter: -exception PayTransactionService: