TX-LCN分布式事务-- TCC事务模式(消费者模块)

 

自己学习用,待补充!

 

对比 LNC模块,就改一下  Controller (注解要换):

@Controller
public class TccController {

    @Autowired
    ConsumerInfoMapper consumerInfoMapper;

    private static ConcurrentHashMap<String,String> maps = new ConcurrentHashMap<>();

    @RequestMapping("/addConsumer-tcc")
    @Transactional(rollbackFor = Exception.class)
    @TccTransaction
    public @ResponseBody String AddConsumer(@RequestBody JSONObject json){

        ConsumerInfo consumerInfo = new ConsumerInfo();
        String id = (String) json.get("id");
        System.out.println("获得Id : "+id);
        maps.put("id",id);
        consumerInfo.setId(id);
        consumerInfo.setName("li");
//        int i = 1/0;
        consumerInfoMapper.insert(consumerInfo);
        return "addConsumer插入成功";
    }

    public String confirmAddConsumer(@RequestBody JSONObject json){

        System.out.println("Consumer--Producer  :"+maps.get("id"));

        return "";
    }

    public String cancelAddConsumer(@RequestBody JSONObject json){

        String id = maps.get("id");
        System.out.println("cancel-id : "+id);
        int i = consumerInfoMapper.deleteByPrimaryKey(id);
        System.out.println("cancel--Consumer  :  " +i);
        return "";
    }


}

 

上一篇:题解 AcWing 1112. 迷宫 & AcWing 1113. 红与黑


下一篇:OpenJ_Bailian - 4115