xiaotanxingchen opened a new issue #99: the message was consumed twice
URL: https://github.com/apache/rocketmq-spring/issues/99
 
 
   **BUG REPORT**
       Recently I encountered a problem, the message was consumed twice. I 
deployed three applications which are same, two of them on the same machine. 
When I send a message,it was consumed twice by the application on the same 
machine. But the other is ok. 
   
   
   ```
   <dependency>
           <groupId>org.apache.rocketmq</groupId>
           <artifactId>rocketmq-spring-boot-starter</artifactId>
           <version>2.0.3</version>
   </dependency>
   ```
   
   `@Service
   @Transactional
   public class TestMqBusinessImpl implements ITestMqBusiness {
   
        private static Logger logger = 
LoggerFactory.getLogger(TestMqBusinessImpl.class);
   
        @Autowired
        IBaseService bs;
        @Autowired
        private RocketMQTemplate rocketMQTemplate;
        /** 
         * {@inheritDoc}   
         * @see org.aurora.mq.business.ITestMqBusiness#get() 
         */
        @Override
        public void get() {
                // TODO Auto-generated method stub
                Message msg1 = 
MessageBuilder.withPayload("测试".getBytes()).build();
                Student st = new Student();
                st.setName("张三");
                TransactionSendResult ret = 
rocketMQTemplate.sendMessageInTransaction("my-group1", "test-topic:tag1", msg1, 
st);
                
                System.out.println(ret.getSendStatus());
                
        }
        
        private void test(Object a){
                Student st = (Student)a;
                System.out.println(st.getName());
                
        }
        
        // Define transaction listener with the annotation 
@RocketMQTransactionListener
       @RocketMQTransactionListener(txProducerGroup ="my-group1")
       class TransactionListenerImpl implements 
RocketMQLocalTransactionListener {
             @Override
             public RocketMQLocalTransactionState 
executeLocalTransaction(Message msg, Object arg) {
                  try {
                          test(arg);
                        } catch (Exception e) {
                                logger.error("消息发送业务逻辑异常,回滚消息", e);
                                return RocketMQLocalTransactionState.ROLLBACK;
                        }
               return RocketMQLocalTransactionState.COMMIT;
             }
   
             @Override
             public RocketMQLocalTransactionState checkLocalTransaction(Message 
msg) {
                  logger.info("checkLocalTransaction");
               return RocketMQLocalTransactionState.COMMIT;
             }
       }
   
   }`
   
   `@Service
   @RocketMQMessageListener(topic = "test-topic", consumerGroup = 
"consumerGroup1", messageModel = MessageModel.CLUSTERING, consumeMode = 
ConsumeMode.ORDERLY)
   public class MyConsumer1 implements RocketMQListener<MessageExt>{
   
        /** 
          * {@inheritDoc}   
          * @see 
org.apache.rocketmq.spring.core.RocketMQListener#onMessage(java.lang.Object) 
          */
        @Override
        public void onMessage(MessageExt message) {
                // TODO Auto-generated method stub
                System.out.println("consumer1:" + message.getMsgId());
        }
   
   }`
   
   
![1](https://user-images.githubusercontent.com/32700417/60633098-bea11e80-9e3b-11e9-8b0e-90162fc5f102.jpg)
   
![2](https://user-images.githubusercontent.com/32700417/60633106-c365d280-9e3b-11e9-8ec9-5ba9f4ff4204.png)
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to