- 使用kafka作为事件通知
- 利用redis作为分布式协调存储
- 使用mysql存储分布式日志(待完善)
- 需要有kafka服务、redis服务
@Component @Order public class TransactionHandleRegister extends TransactionHandleRegisterImpl implements ApplicationRunner { @Override public void run(ApplicationArguments args) throws Exception { Map<String, Class> handleRegisterMap = new HashMap<>(); //增加一个参与者 test,参与操作实例 Test.class handleRegisterMap.put("test", Test.class); super.init(handleRegisterMap); } }
public class Test extends TransactionService { @Override public DistributionTaskInvoke exec(Object... objects) throws Exception { DistributionTaskInvoke rlt = new DistributionTaskInvoke(); //这里写你的事务代码 System.out.println("test exec"); return rlt; } }
@RestController public class TestWeb { @Autowired SendEvent sendEvent;
@RequestMapping("/send/{expects}")
public void send(@PathVariable("expects") String expects) {
sendEvent.send("test", Collections.singleton(expects));
}
}