TX-LCN分布式事务-- TCC事务模式(生产者模块)

 

自己学习用,待补充!

 

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

 

@Controller
public class TccController {

    @Autowired
    ProducerInfoMapper producerInfoMapper;

    @Autowired
    RestTemplate restTemplate;

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


    @RequestMapping("/addProducer-tcc")
    @Transactional(rollbackFor = Exception.class)
    @TccTransaction
    public @ResponseBody String AddProducer(){

        JSONObject json = new JSONObject();
        ProducerInfo producerInfo = new ProducerInfo();
        String id = SnowFlake.nextId()+"";
        System.out.println("获得Id : "+id);
        maps.put("id",id);
        json.put("id",id);
        producerInfo.setId(id);
        producerInfo.setName("li");
        restTemplate.postForEntity("http://localhost:8090/addConsumer-tcc",json,String.class);
        int i = 1/0;
        producerInfoMapper.insert(producerInfo);
        return "addProducer插入成功";
    }

    public String confirmAddProducer(){

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

        return "";
    }

    public String cancelAddProducer(){

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

 

上一篇:【故障处理】队列等待之TX - allocate ITL entry引起的死锁处理(上)


下一篇:孙卫琴的《精通JPA与Hibernate》的读书笔记: 用JPQL批量处理数据