zoukankan      html  css  js  c++  java
  • 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 "";
        }
    
    
    }
  • 相关阅读:
    Spring Boot第四弹,一文教你如何无感知切换日志框架?
    Spring Boot 第三弹,一文带你了解日志如何配置?
    UVa 1625
    UVa 11584
    UVa 11400
    UVa 12563
    UVa 116
    UVa 1347
    UVa 437
    UVa 1025
  • 原文地址:https://www.cnblogs.com/lifan12589/p/14722951.html
Copyright © 2011-2022 走看看