分布式事物 seata
This commit is contained in:
parent
641a33d27d
commit
95c07fcc1b
|
|
@ -0,0 +1,22 @@
|
|||
package com.czg.controller;
|
||||
|
||||
import com.czg.account.service.TestService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author GYJoker
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/test")
|
||||
public class TestController {
|
||||
|
||||
@Resource
|
||||
private TestService testService;
|
||||
|
||||
@RequestMapping("/hello")
|
||||
public String hello() {
|
||||
return testService.insertData();
|
||||
}
|
||||
}
|
||||
|
|
@ -23,10 +23,10 @@ dubbo:
|
|||
application:
|
||||
name: account-server
|
||||
qos-port: 22221
|
||||
qos-enable: true
|
||||
# qos-enable: true
|
||||
registry:
|
||||
address: nacos://121.40.109.122:8848 # Nacos 服务地址
|
||||
group: server
|
||||
group: server-dev
|
||||
namespace: 237e1905-0a66-4375-9bb6-a51c3c034aca
|
||||
protocol:
|
||||
port: 9101
|
||||
|
|
@ -34,3 +34,13 @@ dubbo:
|
|||
threadpool: fixed
|
||||
|
||||
|
||||
seata:
|
||||
application-id: account-server
|
||||
tx-service-group: group_seata
|
||||
config:
|
||||
type: nacos
|
||||
nacos:
|
||||
server-addr: 121.40.109.122:8848
|
||||
namespace:
|
||||
group: group_seata
|
||||
|
||||
|
|
|
|||
|
|
@ -34,3 +34,15 @@ dubbo:
|
|||
threads: 20
|
||||
threadpool: fixed
|
||||
|
||||
|
||||
|
||||
seata:
|
||||
application-id: account-server
|
||||
tx-service-group: group_seata
|
||||
config:
|
||||
type: nacos
|
||||
nacos:
|
||||
server-addr: 121.40.109.122:8848
|
||||
namespace:
|
||||
group: group_seata
|
||||
|
||||
|
|
|
|||
|
|
@ -33,12 +33,19 @@ dubbo:
|
|||
# qos-enable: true
|
||||
registry:
|
||||
address: nacos://121.40.109.122:8848 # Nacos 服务地址
|
||||
group: server
|
||||
group: server-dev
|
||||
namespace: 237e1905-0a66-4375-9bb6-a51c3c034aca
|
||||
protocol:
|
||||
port: 9101
|
||||
port: 9201
|
||||
threads: 20
|
||||
threadpool: fixed
|
||||
|
||||
rabbitmq:
|
||||
prefix: dev_
|
||||
seata:
|
||||
application-id: order-server
|
||||
tx-service-group: group_seata
|
||||
config:
|
||||
type: nacos
|
||||
nacos:
|
||||
server-addr: 121.40.109.122:8848
|
||||
namespace:
|
||||
group: group_seata
|
||||
|
|
|
|||
|
|
@ -37,10 +37,18 @@ dubbo:
|
|||
group: server-test
|
||||
namespace: 237e1905-0a66-4375-9bb6-a51c3c034aca
|
||||
protocol:
|
||||
port: 9101
|
||||
port: 9201
|
||||
threads: 20
|
||||
threadpool: fixed
|
||||
|
||||
|
||||
rabbitmq:
|
||||
prefix: test_
|
||||
seata:
|
||||
application-id: order-server
|
||||
tx-service-group: group_seata
|
||||
config:
|
||||
type: nacos
|
||||
nacos:
|
||||
server-addr: 121.40.109.122:8848
|
||||
namespace:
|
||||
group: group_seata
|
||||
|
||||
|
|
|
|||
|
|
@ -38,9 +38,19 @@ dubbo:
|
|||
qos-enable: true
|
||||
registry:
|
||||
address: nacos://121.40.109.122:8848 # Nacos 服务地址
|
||||
group: server
|
||||
group: server-dev
|
||||
namespace: 237e1905-0a66-4375-9bb6-a51c3c034aca
|
||||
protocol:
|
||||
port: 9101
|
||||
port: 9301
|
||||
threads: 20
|
||||
threadpool: fixed
|
||||
|
||||
seata:
|
||||
application-id: product-server
|
||||
tx-service-group: group_seata
|
||||
config:
|
||||
type: nacos
|
||||
nacos:
|
||||
server-addr: 121.40.109.122:8848
|
||||
namespace:
|
||||
group: group_seata
|
||||
|
|
|
|||
|
|
@ -30,7 +30,17 @@ dubbo:
|
|||
group: server-test
|
||||
namespace: 237e1905-0a66-4375-9bb6-a51c3c034aca
|
||||
protocol:
|
||||
port: 9101
|
||||
port: 9301
|
||||
threads: 20
|
||||
threadpool: fixed
|
||||
|
||||
|
||||
seata:
|
||||
application-id: product-server
|
||||
tx-service-group: group_seata
|
||||
config:
|
||||
type: nacos
|
||||
nacos:
|
||||
server-addr: 121.40.109.122:8848
|
||||
namespace:
|
||||
group: group_seata
|
||||
|
|
|
|||
|
|
@ -39,3 +39,14 @@ dubbo:
|
|||
port: 9401
|
||||
threads: 20
|
||||
threadpool: fixed
|
||||
|
||||
seata:
|
||||
application-id: system-server
|
||||
tx-service-group: group_seata
|
||||
config:
|
||||
type: nacos
|
||||
nacos:
|
||||
server-addr: 121.40.109.122:8848
|
||||
namespace:
|
||||
group: group_seata
|
||||
|
||||
|
|
|
|||
|
|
@ -39,3 +39,15 @@ dubbo:
|
|||
port: 9401
|
||||
threads: 20
|
||||
threadpool: fixed
|
||||
|
||||
|
||||
seata:
|
||||
application-id: system-server
|
||||
tx-service-group: group_seata
|
||||
config:
|
||||
type: nacos
|
||||
nacos:
|
||||
server-addr: 121.40.109.122:8848
|
||||
namespace:
|
||||
group: group_seata
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
package com.czg.account.service;
|
||||
|
||||
/**
|
||||
* @author GYJoker
|
||||
*/
|
||||
public interface TestService {
|
||||
String insertData();
|
||||
}
|
||||
|
|
@ -32,6 +32,7 @@
|
|||
<dubbo-spring.version>3.3.3</dubbo-spring.version>
|
||||
<dubbo-registry-nacos.version>3.3.3</dubbo-registry-nacos.version>
|
||||
<dubbo.version>3.3.3</dubbo.version>
|
||||
<seata.version>2.0.0</seata.version>
|
||||
<alipay-sdk-java.version>4.40.54.ALL</alipay-sdk-java.version>
|
||||
<aliyun-sms.version>2.0.24</aliyun-sms.version>
|
||||
<aliyun.oss.version>2.8.3</aliyun.oss.version>
|
||||
|
|
@ -159,6 +160,13 @@
|
|||
<artifactId>dubbo</artifactId>
|
||||
<version>${dubbo.version}</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/io.seata/seata-spring-boot-starter -->
|
||||
<dependency>
|
||||
<groupId>io.seata</groupId>
|
||||
<artifactId>seata-spring-boot-starter</artifactId>
|
||||
<version>${seata.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>org.quartz-scheduler</groupId>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,49 @@
|
|||
package com.czg.service.account.service.impl;
|
||||
|
||||
import com.czg.account.entity.UserInfo;
|
||||
import com.czg.account.service.TestService;
|
||||
import com.czg.account.service.UserInfoService;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.system.dto.SysParamsDTO;
|
||||
import com.czg.system.service.SysParamsService;
|
||||
import io.seata.spring.annotation.GlobalTransactional;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author GYJoker
|
||||
*/
|
||||
@Service
|
||||
public class TestServiceImpl implements TestService {
|
||||
|
||||
@Resource
|
||||
private UserInfoService userInfoService;
|
||||
|
||||
@DubboReference
|
||||
private SysParamsService sysParamsService;
|
||||
|
||||
@Override
|
||||
@GlobalTransactional
|
||||
public String insertData() {
|
||||
|
||||
SysParamsDTO paramsDTO = new SysParamsDTO();
|
||||
paramsDTO.setParamCode("test22222");
|
||||
CzgResult<String> czgResult = sysParamsService.insertParams(paramsDTO);
|
||||
System.out.println(czgResult);
|
||||
if (czgResult.getCode() != 200){
|
||||
throw new RuntimeException("insert params error");
|
||||
}
|
||||
|
||||
UserInfo userInfo = new UserInfo();
|
||||
userInfo.setPhone("18812345678");
|
||||
userInfo.setPassword("123456");
|
||||
|
||||
userInfoService.save(userInfo);
|
||||
|
||||
|
||||
|
||||
|
||||
return "insert data success";
|
||||
}
|
||||
}
|
||||
|
|
@ -80,6 +80,11 @@
|
|||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.seata</groupId>
|
||||
<artifactId>seata-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||
|
|
|
|||
Loading…
Reference in New Issue