kiritokun07 opened a new issue #395:
URL: https://github.com/apache/rocketmq-spring/issues/395


   1.环境
   ```
   <parent>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-parent</artifactId>
           <version>2.4.2</version>
           <relativePath/> <!-- lookup parent from repository -->
   </parent>
   
   <dependency>
   <groupId>org.apache.rocketmq</groupId>
   <artifactId>rocketmq-spring-boot-starter</artifactId>
   <version>2.2.1</version>
   </dependency>
   ```
   2.我做了什么
   
简单实现了RocketMQLocalTransactionListener接口的两个方法,都是返回`RocketMQLocalTransactionState.COMMIT`
   ```
   @Service
   @RocketMQTransactionListener
   public class OrderServiceImpl4Listener implements 
RocketMQLocalTransactionListener {
   }
   ```
   在Controller中发送了一个事务消息
   ```
   @Resource
       private RocketMQTemplate rocketMQTemplate;
   @RequestMapping("/test2")
       public void test2() {
           Message<String> message = MessageBuilder.withPayload("发送了一个事务消息")
                   .setHeader(RocketMQHeaders.TRANSACTION_ID,"KEY_").build();
           rocketMQTemplate.sendMessageInTransaction(topic, message, null);
   }
   
   ```
   3.报错
   >java.lang.IllegalStateException: The rocketMQTemplate does not exist 
TransactionListener at 
org.apache.rocketmq.spring.core.RocketMQTemplate.sendMessageInTransaction(RocketMQTemplate.java:1014)
 ~[rocketmq-spring-boot-2.2.1.jar:2.2.1]
   进入`sendMessageInTransaction`方法后,因为`transactionListener`不存在抛出异常了
   
   这篇文章说:In sendMessageInTransaction(), the first parameter transaction name 
("test") must be same with the @RocketMQTransactionListener's member field 
'transName'
   但是由于版本的问题,我没有办法设置transName
   
[事务消息](https://github.com/apache/rocketmq-spring/wiki/%E4%BA%8B%E5%8A%A1%E6%B6%88%E6%81%AF)
   我也曾试图使用一个新的Template,然后在Controller中注入新的template,但是仍然报错
   ```
   @ExtRocketMQTemplateConfiguration
   public class ExtRocketMQTemplate extends RocketMQTemplate {
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to