-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from maihaoche/mq-4.3.0
跟进rocketmq 4.3.0 版本
- Loading branch information
Showing
8 changed files
with
160 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/com/maihaoche/starter/mq/annotation/MQTransactionProducer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.maihaoche.starter.mq.annotation; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import java.lang.annotation.*; | ||
|
||
/** | ||
* Created by pufang on 2018/7/26. | ||
* RocketMQ事务消息生产者 | ||
*/ | ||
@Target(ElementType.TYPE) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Documented | ||
@Component | ||
public @interface MQTransactionProducer { | ||
|
||
/** | ||
* *重要* 事务的反查是基于同一个producerGroup为维度 | ||
*/ | ||
String producerGroup(); | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/com/maihaoche/starter/mq/base/AbstractMQTransactionProducer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.maihaoche.starter.mq.base; | ||
|
||
import com.maihaoche.starter.mq.MQException; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.rocketmq.client.producer.SendResult; | ||
import org.apache.rocketmq.client.producer.SendStatus; | ||
import org.apache.rocketmq.client.producer.TransactionListener; | ||
import org.apache.rocketmq.client.producer.TransactionMQProducer; | ||
import org.apache.rocketmq.common.message.Message; | ||
|
||
/** | ||
* Created by pufang on 20180726. | ||
* RocketMQ的事务生产者的抽象基类 | ||
*/ | ||
@Slf4j | ||
public abstract class AbstractMQTransactionProducer implements TransactionListener { | ||
|
||
private TransactionMQProducer transactionProducer; | ||
|
||
public void setProducer(TransactionMQProducer transactionProducer) { | ||
this.transactionProducer = transactionProducer; | ||
} | ||
|
||
public SendResult sendMessageInTransaction(Message msg, Object arg) throws MQException { | ||
try { | ||
SendResult sendResult = transactionProducer.sendMessageInTransaction(msg, arg); | ||
if(sendResult.getSendStatus() != SendStatus.SEND_OK) { | ||
log.error("事务消息发送失败,topic : {}, msgObj {}", msg.getTopic(), msg); | ||
throw new MQException("事务消息发送失败,topic :" + msg.getTopic() + ", status :" + sendResult.getSendStatus()); | ||
} | ||
log.info("发送事务消息成功,事务id: {}", msg.getTransactionId()); | ||
return sendResult; | ||
} catch (Exception e) { | ||
log.error("事务消息发送失败,topic : {}, msgObj {}", msg.getTopic(), msg); | ||
throw new MQException("事务消息发送失败,topic :" + msg.getTopic() + ",e:" + e.getMessage()); | ||
} | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters