update to v1.4.0
This commit is contained in:
+21
@@ -0,0 +1,21 @@
|
||||
package org.txlcn.demo;
|
||||
|
||||
import com.codingapi.txlcn.tc.config.EnableDistributedTransaction;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2018/12/25
|
||||
*
|
||||
* @author ujued
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableDiscoveryClient
|
||||
@EnableDistributedTransaction
|
||||
public class ServiceAApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ServiceAApplication.class, args);
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package org.txlcn.demo.servicea;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2018/12/25
|
||||
*
|
||||
* @author ujued
|
||||
*/
|
||||
@RestController
|
||||
public class DemoController {
|
||||
|
||||
private final DemoService demoService;
|
||||
|
||||
@Autowired
|
||||
public DemoController(DemoService demoService) {
|
||||
this.demoService = demoService;
|
||||
}
|
||||
|
||||
@RequestMapping("/txlcn")
|
||||
public String execute(@RequestParam("value") String value, @RequestParam(value = "ex", required = false) String exFlag
|
||||
, @RequestParam(value = "f", required = false) String flag) {
|
||||
return demoService.execute(value, exFlag, flag);
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package org.txlcn.demo.servicea;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.txlcn.demo.common.db.mapper.BaseDemoMapper;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2018/12/25
|
||||
*
|
||||
* @author ujued
|
||||
*/
|
||||
@Mapper
|
||||
public interface DemoMapper extends BaseDemoMapper {
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package org.txlcn.demo.servicea;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2018/12/25
|
||||
*
|
||||
* @author ujued
|
||||
*/
|
||||
public interface DemoService {
|
||||
|
||||
String execute(String value, String ex, String flag);
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package org.txlcn.demo.servicea;
|
||||
|
||||
import com.codingapi.txlcn.common.util.Transactions;
|
||||
import com.codingapi.txlcn.tc.annotation.LcnTransaction;
|
||||
import com.codingapi.txlcn.tracing.TracingContext;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.txlcn.demo.common.db.domain.Demo;
|
||||
import org.txlcn.demo.common.spring.ServiceBClient;
|
||||
import org.txlcn.demo.common.spring.ServiceCClient;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2018/12/25
|
||||
*
|
||||
* @author ujued
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class DemoServiceImpl implements DemoService {
|
||||
@Resource
|
||||
private DemoMapper demoMapper;
|
||||
@Resource
|
||||
private ServiceBClient serviceBClient;
|
||||
@Resource
|
||||
private ServiceCClient serviceCClient;
|
||||
|
||||
@LcnTransaction
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public String execute(String value, String exFlag, String flag) {
|
||||
String dResp = serviceBClient.rpc(value);
|
||||
// step2. call remote ServiceB
|
||||
String eResp = serviceCClient.rpc(value);
|
||||
// step3. execute local transaction
|
||||
Demo demo = new Demo();
|
||||
demo.setGroupId(TracingContext.tracing().groupId());
|
||||
demo.setDemoField(value);
|
||||
demo.setCreateTime(new Date());
|
||||
demo.setAppName(Transactions.getApplicationId());
|
||||
demoMapper.save(demo);
|
||||
|
||||
// 置异常标志,DTX 回滚
|
||||
if (Objects.nonNull(exFlag)) {
|
||||
throw new IllegalStateException("by exFlag");
|
||||
}
|
||||
|
||||
return dResp + " > " + eResp + " > " + "ok-service-a";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
spring:
|
||||
datasource:
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
url: jdbc:mysql://${zlt.datasource.ip}:3306/txlcn-demo?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull
|
||||
username: ${zlt.datasource.username}
|
||||
password: ${zlt.datasource.password}
|
||||
|
||||
## tx-manager 配置
|
||||
tx-lcn:
|
||||
ribbon:
|
||||
loadbalancer:
|
||||
dtx:
|
||||
enabled: true
|
||||
logger:
|
||||
enabled: true
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
jdbc-url: jdbc:mysql://${zlt.datasource.ip}:3306/tx_logger?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull
|
||||
username: ${zlt.datasource.username}
|
||||
password: ${zlt.datasource.password}
|
||||
@@ -0,0 +1,14 @@
|
||||
server:
|
||||
port: 12011
|
||||
|
||||
zlt:
|
||||
nacos:
|
||||
server-addr: 192.168.28.130:8848
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: txlcn-demo-spring-service-a
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: ${zlt.nacos.server-addr}
|
||||
Reference in New Issue
Block a user