dromara / myth Goto Github PK
View Code? Open in Web Editor NEWReliable messages resolve distributed transactions
Home Page: https://dromara.org
License: Apache License 2.0
Reliable messages resolve distributed transactions
Home Page: https://dromara.org
License: Apache License 2.0
demo工程下单业务中,保存订单信息和记录事务日志信息不在同一个库
application.yml配置的是业务数据库的连接信息
applicationContext.xml中配置的是事务日志连接信息
这是在同一个服务中分别操作了两个数据库的数据,这本质上也是一个分布式事务,这块是否需要保证数据的一致性?
IDEA 有一个选项配置Java Compiler,这里我的设置选择了eclipse,elipse的编译方式不直接支持lombok
应该选择javac,因为javac是支持lombok的编译方式
而maven是使用的javac编译器,因此运行mvn命令不会出错
用xml不能config全局配置 每个服务都需要修改实在是不太理想
为什么不考虑直接使用spring的mq配置,或者自定义配置而不是 使用xml呢
生产者消费者的交换器,路由key 是不一致的,如果自己不修改直接用rabbitmq 跑demo 流程不通,还是有哪里可以配置我没找到?
我在消减库存的事务中除以0,让事务出现异常,结果事务日志状态显示提交成功,订单状态也显示支付成功,这是否是正常现象?
我先在acount的service抛出一个异常,然后执行order,去掉抛出异常的代码,让其能够正常执行,重启acount的服务,结果用户余额一直被扣
当扣除余额的操作未发生异常,而减库存操作发生了异常时,扣除余额的数据库操作正常进行提交,并不会回滚。
目前Spring-Cloud的事务时通过FeignClient传播的,能否支持RestTemplate方式?
为了适应现有项目,我讲dubbo升级到2.8.2,spring升级到5.0.7.RELEASE。然后大致在com.github.myth.core.service.handler.ActorMythTransactionHandler#handler中,执行demo到协调inventoryService的事务时,mythTransactionContext为null,导致消息没有发送出去。
我配置的是通过文件保存本地事务日志,遇到这个错误
fail to write transaction to local storage
在基于消息的分布式事务中,发起者通过中间消息服务通知参与者,如果发起者失败会回滚,但如果参与者失败又该怎么通知到发起者?
项目中有四个库
事务日志库,对应着有
message_account_service(账户事务日志表)
message_order_service(订单事务日志表)
message_inventory_service(库存事务日志表)
订单库:有表 order
账户库: 有表 account
库存库:有表 inventory
现有以下几个情况:
1、下单时,扣减账户和扣减库存都是成功的;但在订单服务的最后可能发生了异常,此时账户和订单的事务日志表记得的状态都是成功的,订单事务日志表的状态是失败;此时要怎么处理?(重试的方式执行下单操作吗,可现在的表里没有记录下单时的参数信息)
2、下单时,扣减账户失败,扣减库存成功;此时账户的事务日志表状态是失败,订单和库存的事务日志表状态是成功;此时要怎么处理?
现有两种情况可供作者分析
第一种:myth框架的demo正常,可恢复。 在我原来的项目中(非myth目录),添加myth框架支持。
尝试启动eureka,myth-demo-springcloud-account,myth-demo-springcloud-inventory, 我自己的项目(做为消费者远程调用account,inventory服务),一切正常,包括停掉account或者inventory服务,重启恢复也正常
第二种:将account服务复制拷贝一份到我的项目下,目前只修改了pom文件的parent,正常流程是通的,消息恢复服务 依然不通,account复制服务消费消息恢复时 依旧报错No qualifying bean of type 'xxx.xxx' available
希望作者早点看到,我在QQ群里
能不要吗,感觉不太适用 在 springcloud 框架中,比如,account服务,account-api就 应该只能account服务用,别的服务不能用
你好,myth是否必须需要配置数据库保存事务日志
采用的是强一致性还是最终一致性?
您好,建议对稳定的版本做发布,现在只看到1.0版本。
Hi, there are multiple versions of org.slf4j:slf4j-api in myth-master\myth-rpc\myth-motan. As shown in the following dependency tree, according to Maven's “nearest wins” strategy, only org.slf4j:slf4j-api:1.7.25 can be loaded, and org.slf4j:slf4j-api:1.5.8 will be shadowed.
As org.slf4j:slf4j-api:1.5.8 has not been loaded during the building process, several methods are missing. However, the missing methods:
1. org.slf4j.helpers.MessageFormatter: java.lang.String format(java.lang.String,java.lang.Object)
The above missing methods are actually referenced by myth-master\myth-rpc\myth-motan, which will cause “NoSuchMethodErrors” at runtime.
Suggested fixing solutions:
Please let me know which solution do you prefer? I can submit a PR to fix it.
Thank you very much for your attention.
Best regards,
Dependency tree----
目前只有源码和源码讲解,缺少总体的架构图。
2018-08-22 16:37:57.126 ERROR 10168 --- [ruptor-thread-1] .g.m.c.d.p.MythTransactionEventPublisher : Disruptor handleEventException:2MythTransaction(transId=891075360, status=1, role=3, retriedCount=0, createTime=Wed Aug 22 16:36:22 CST 2018, lastTime=Wed Aug 22 16:36:22 CST 2018, version=1, targetClass=com.github.myth.demo.springcloud.account.service.impl.AccountServiceImpl, targetMethod=payment, errorMsg=null, mythParticipants=[])org.apache.zookeeper.KeeperException$NodeExistsException: KeeperErrorCode = NodeExists for /myth-account-service/891075360
不能保证分布式事物,我在order服务方法最后一行抛了一个异常,但我余额和库存都扣减了
代码里面保证一致性最重要的一环就是基于finally去sendmsg保证异常的时候能够把消息发到消息队列,从而保证最终一致性,有几种异常情况处理不了,列举一种:本地操作了数据库之后(orderPay的orderMapper.save刚好执行完成),本地程序挂了。。这时候因为在orderservice上面没有本地事务,order保存是成功的,但是消息队列里面没有消息,账号和库存服务都拿不到相应要执行的东西,事务不一致了
最新版的spring-amqp已经把CorrelationData 已经从support包转移到connection中
spring-projects/spring-amqp@91f79aa#diff-b7d7d12259936f90e48a6ed6984b7d53
如最后一个用户购买成功后,启用订单系统,在调关闭产品系统的优惠功能,然后再调积分系统,最后调仓库系统减商品数量。如果订单系统在掉积分系统成功后,断电了?消息事物还成立吗?
好像kafka消息的发送与接收做不到绝对可靠,不适合高可用场景
最新的项目下载后,配置后,试着手动关掉掉一些项目,比如说(order,inventory,account,eruka等)重启后,数据并无恢复功能。
以 demo中的 myth-demo-spring-cloud-inventory 为例,
order 模块的 PaymentServiceImpl.makePayment 先询问了 account 模块的余额 和 inventory 模块的 库存, 假设目前 余额和库存 都足够, 然后 发起了 accountClient.payment 和 inventoryClient.decrease
这时 accountClient.payment 正常执行了。
而 inventoryClient.decrease 由于 并发的存在, 可能这时 库存已经被别人的订单 减为 0, 从而 这次的 inventoryClient.decrease 抛出了 MythRuntimeException("spring cloud inventory-service 库存不足!")
那这种情况下, account 模块 应该不会被回滚吧? 是不是 只能用tcc 方法来解决这些问题, 可靠消息 只能 保证 减库存操作一定被发送到, 但能不能扣减成功就没办法了?
感谢作者大大,提供了分布式事务的实现方案,让我可以作为学习和参考的基础.
通过对框架的理解,个人实现了阿里云MQ的方式.
不知道是否可以提交到一个分支.
[log-disruptor-2] o.d.m.c.s.r.JdbcCoordinatorRepository : executeUpdate-> wait millis 60000, active 0, maxActive 100
mq消息监听时,重试方法时,会进入到AOP切面获取request;但实际上这个不是Feign调用,
无法获取request;
异常代码:
RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
异常
java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
看了流程图,都是子系统同步调用,如果异步交互的情况下,有可能实现完整事务吗?
springcloud达不到最终一致
我修改了一下业务代码,把我的钱变成0,特地让程序报异常,钱不是扣了,但是订单和库存还是扣了,myth可能做到全部回滚不?我看了其他人的问题,这个程序不管怎么搞,订单还是会生成的。最后还是想问问能不能一次性回滚,像lcn那样。
直接从git拉取下来的master分支,运行eureka
抛错:Caused by: java.lang.ClassNotFoundException: org.apache.http.util.Args
需添加
http-core jar eureka才能运行
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.