Skip to content

Commit

Permalink
将 pay 模块接入 SCA Dubbo 和 Nacos Discovery 组件,同时将 Seata 修改成 SCA Seata 组件
Browse files Browse the repository at this point in the history
  • Loading branch information
YunaiV committed Apr 12, 2020
1 parent 8aedbbc commit a0e9687
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 164 deletions.
32 changes: 11 additions & 21 deletions pay/pay-service-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,22 @@
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>

<!-- RPC 相关 -->
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-spring</artifactId>
</dependency>
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-dubbo</artifactId>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-dubbo</artifactId>
</dependency>

<!-- RPC 相关 -->
<!-- Registry 和 Config 相关 -->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>

<!-- Transaction 相关 -->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-seata</artifactId>
</dependency>

<!-- MQ 相关 -->
Expand Down Expand Up @@ -99,16 +98,6 @@
<type>jar</type>
</dependency>

<!-- Registry 和 Config 相关 -->
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
</dependency>

<!-- 测试相关 -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -143,4 +132,5 @@
<url>http://jcenter.bintray.com</url>
</repository>
</repositories>

</project>
Original file line number Diff line number Diff line change
@@ -1,48 +1,12 @@
package cn.iocoder.mall.pay.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.pay.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);
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
spring:
# datasource
datasource:
url: jdbc:mysql://192.168.88.14:3306/mall_pay?useSSL=false&useUnicode=true&characterEncoding=UTF-8
driver-class-name: com.mysql.jdbc.Driver
username: root
password: ${MALL_MYSQL_PASSWORD}

# xxl-job
xxl:
job:
Expand All @@ -18,9 +10,3 @@ xxl:
logpath: /Users/yunai/logs/xxl-job/
logretentiondays: 1
accessToken:

# rocketmq
rocketmq:
name-server: 192.168.88.14:9876
producer:
group: pay-producer-group
30 changes: 23 additions & 7 deletions pay/pay-service-impl/src/main/resources/config/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,31 @@ spring:
username: root
password: ${MALL_MYSQL_PASSWORD}

# Spring Cloud 配置项
cloud:
nacos:
# Spring Cloud Nacos Discovery 配置项
discovery:
server-addr: 127.0.0.1:8848 # Nacos 服务器地址

# mybatis
mybatis-plus:
config-location: classpath:mybatis-config.xml
mapper-locations: classpath:mapper/*.xml
type-aliases-package: cn.iocoder.mall.pay.biz.dataobject

# dubbo
# Dubbo 配置项
dubbo:
application:
name: pay-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 # 设置订阅的应用列表,默认为 * 订阅所有应用
# Dubbo 提供者的协议
protocol:
port: -1
name: dubbo
port: -1
scan:
base-packages: cn.iocoder.mall.pay.biz.service
provider:
Expand All @@ -36,6 +46,12 @@ rocketmq:
producer:
group: pay-producer-group

# 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 分组
69 changes: 0 additions & 69 deletions pay/pay-service-impl/src/main/resources/file.conf

This file was deleted.

14 changes: 0 additions & 14 deletions pay/pay-service-impl/src/main/resources/registry.conf

This file was deleted.

13 changes: 12 additions & 1 deletion pay/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,16 @@
<module>pay-service-impl</module>
</modules>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>common-dependencies</artifactId>
<version>1.0-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dubbo:
address: spring-cloud://127.0.0.1:8848 # 指定 Dubbo 服务注册中心的地址
# Spring Cloud Alibaba Dubbo 专属配置
cloud:
subscribed-services: 'admin-application' # 设置订阅的应用列表,默认为 * 订阅所有应用
subscribed-services: admin-application # 设置订阅的应用列表,默认为 * 订阅所有应用
# Dubbo 提供者的协议
protocol:
name: dubbo
Expand Down Expand Up @@ -62,6 +62,6 @@ seata:
registry:
type: nacos # 注册中心类型
nacos:
serverAddr: 127.0.0.1:8848 # Nacos 服务地址
serverAddr: ${spring.cloud.nacos.discovery.server-addr} # Nacos 服务地址
namespace: # Nacos 命名空间
cluster: default # 使用的 Seata 分组

0 comments on commit a0e9687

Please sign in to comment.