Skip to content

Latest commit

 

History

History
 
 

sofarpc-saga-sample

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Seata Saga 模式 demo 工程

Seata 是一款开源的分布式事务解决方案,提供高性能和简单易用的分布式事务服务。

基于 Seata Saga模式,演示分布式事务的提交和回滚;

本demo中一个分布式事务内会有2个Saga事务参与者,分别是: InventoryActionBalanceAction ;分布式事务提交则两者均提交,分布式事务回滚则两者均回滚;

这2个Saga参与者均是 sofa-rpc 服务,两个参与都有一个reduce方法,表示库存扣减或余额扣减,还有一个compensateReduce方法,表示补偿扣减操作。

  • InventoryAction 接口定义如下:
public interface InventoryAction {

    /**
     * reduce
     * @param businessKey
     * @param amount
     * @param params
     * @return
     */
    boolean reduce(String businessKey, BigDecimal amount, Map<String, Object> params);

    /**
     * compensateReduce
     * @param businessKey
     * @param params
     * @return
     */
    boolean compensateReduce(String businessKey, Map<String, Object> params);
}

demo 运行指南

step 1 启动 SEATA Server

运行 SeataServerStarter ,启动 Seata Server;

step 2 启动 sofa-rpc provider Demo

运行 SofaRpcSagaProviderApplication ,启动 sofa-rpc provider;

step 3 启动 Saga Demo

运行 SofaRPCSagaTransactionApplication , 启动 demo工程;

内含Saga 调用sofa-rpc 事务提交场景和Saga 调用sofa-rpc 事务回滚场景的演示.