Giter VIP home page Giter VIP logo

transaction-mq's Introduction

分布式事务处理方案-使用消息队列达到最终一致性

本项目是基于dubbo构建的消息服务,和之前的dubbo构建微服务是一套代码

https://github.com/yinjihuan/micro-service-dubbo

  • cxytiandi-transaction-mq-api-interface dubbo 接口定义,包含实体类
  • cxytiandi-transaction-mq-manager 后台管理,可以管理消息的消费情况,有无死亡消息,手动重发消息等等(还未实现)
  • cxytiandi-transaction-mq-service 消息处理服务
  • cxytiandi-transaction-mq-task 消息发送任务

消息表结构请参考:

https://github.com/yinjihuan/transaction-mq/blob/master/cxytiandi-transaction-mq/cxytiandi-transaction-mq-api-interface/src/main/java/com/cxytiandi/transaction/mq/api/po/TransactionMessage.java

数据库用mysql,ORM框架自己封装的:https://github.com/yinjihuan/smjdbctemplate

使用

注入消息队列的dubbo服务即可发送消息, 消息队列用的activemq

我们在A服务中修改信息,同时需要修改B服务中的数据,这个时候就产生分布式事务了

@Reference(interfaceClass = TransactionMessageRpcService.class, version = "1.0.0", check = false, mock = "true")

@Transactional(rollbackFor = Exception.class)
public void update(LouDong louDong) {
    LouDong old = super.getById("id", louDong.getId());
    super.update(louDong, "id");
		
    //发送消息,修改房号中的小区名称
    TransactionMessage message = new TransactionMessage();
    message.setQueue("fangjia.dis_name_queue");
    message.setCreateDate(new Date()); 
    message.setSendSystem(Constants.FJ_LD_SYS_NAME);
    message.setMessage(JsonUtils.toJson(
		    new UpdateHouseNameDto(louDong.getCity(), louDong.getRegion(), old.getName(), louDong.getName())
    ));
    boolean reuslt = transactionMessageRpcService.sendMessage(message);
    if (!reuslt) {
	    throw new RuntimeException("回滚事务");
    }
}

transaction-mq's People

Contributors

yinjihuan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.