提交 747232ef authored 作者: 陈世营's avatar 陈世营

sharding Test

上级 146e7ca5
......@@ -3,8 +3,8 @@ package com.loit.seata.order.example.service.biz;
import com.loit.seata.order.example.model.Order;
import com.loit.seata.order.example.repository.OrderDAO;
import com.loit.seata.order.example.service.comsumer.AccountFeignClient;
import com.loit.seata.order.example.service.comsumer.ShardingSeataExampleFeignClient;
import com.loit.seata.order.example.service.comsumer.StorageFeignClient;
import io.seata.spring.annotation.GlobalLock;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -19,6 +19,10 @@ public class OrderService {
private AccountFeignClient accountFeignClient;
@Resource
private StorageFeignClient storageFeignClient;
@Resource
private ShardingSeataExampleFeignClient shardingSeataExampleFeignClient;
@Resource
private OrderDAO orderDAO;
......@@ -60,4 +64,19 @@ public class OrderService {
accountFeignClient.reduce(userId, orderMoney);
}
@GlobalTransactional
@Transactional(rollbackFor = Exception.class)
public void shardingSeataTest(String userId, String commodityCode, Integer count) {
BigDecimal orderMoney = new BigDecimal(count).multiply(new BigDecimal(5));
Order order = new Order()
.setUserId(userId)
.setCommodityCode(commodityCode)
.setCount(count)
.setMoney(orderMoney);
orderDAO.insert(order);
shardingSeataExampleFeignClient.purchase();
throw new RuntimeException("shardingSeataTest");
}
}
package com.loit.seata.order.example.service.comsumer;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
@FeignClient(name = "loit-shardingshere")
public interface ShardingSeataExampleFeignClient {
@GetMapping("demo/purchase")
void purchase();
}
......@@ -88,4 +88,11 @@ public class OrderController {
public BaseResponse echo() {
return BaseResponse.ofSuccess(true);
}
@GetMapping("/shardingSeataTest")
public BaseResponse shardingSeataTest() {
orderService.shardingSeataTest("1", "product-2", 1);
return BaseResponse.ofSuccess(true);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论