分布式事务

来源:9-23 Spring Cloud Stream + RocketMQ实现分布式事务01-重构生产者

慕村9469909

2020-03-18

stream:
      rocketmq:
        binder:
          name-server: 129.211.164.53:9876
        bindings:
          output:
            producer:
              transactional: true
              group: tx-user-coupon-group
      bindings:
        output:
            #用来指定Topic
          destination: coupon-infoss
        my_output:
          destination: my-infos

maven 配置

<dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-stream-rocketmq</artifactId>
 </dependency>

这么处理之后 一般信息就无法发送到 MQ 控制台,也不报错 尴尬。急急急

请求结果

"error": "Internal Server Error",
    "message": "failed to send Message to channel 'output'; nested exception is java.lang.IllegalStateException: Failed to convert message: 'GenericMessage [payload=UserCouPonDto.UserCouPonDtoBuilder(userId=1, type=3), headers={id=071e57d0-03e2-d444-a28d-4181f17bd1dc, TRANSACTION_ID=752b842e-5974-467e-8553-e2ec6bc19fc3, contentType=application/json, dto={\"id\":1,\"sex\":3}, timestamp=1584525219256}]' to outbound message.",
    "path": "/user/update"
写回答

2回答

大目

2020-03-20

//img.mukewang.com/szimg/5e739a4f098dd73528200446.jpg


如图,你的本地事务,因为sex没有设置,所以会回滚。因此消息永远都会走ROLLBACK。

建议以后养成良好的习惯,catch到异常后,不管三七二十一,打个日志先哈。

解决方法:

  1. 将sex非空约束去掉,或者设置默认值;

  2. 在com.wxzm.user.service.impl.UserInfoServiceImpl#auditByIdInDB设置sex的值。

0
0

大目

2020-03-18

请问有完整的代码吗?我来看看

0
4
慕村9469909
回复
大目
麻烦您看一下了。
2020-03-19
共4条回复

Spring Cloud Alibaba微服务从入门到进阶

面向未来微服务:熟练掌握Spring Cloud Alibaba

3083 学习 · 1324 问题

查看课程