16
16
*/
17
17
package org .apache .seata .integration .rocketmq ;
18
18
19
- import org .apache .rocketmq .client .producer .SendStatus ;
20
- import org .apache .seata .common .util .StringUtils ;
21
- import org .apache .seata .core .context .RootContext ;
22
- import org .apache .seata .core .model .GlobalStatus ;
23
- import org .apache .seata .rm .DefaultResourceManager ;
24
19
import org .apache .rocketmq .client .Validators ;
25
20
import org .apache .rocketmq .client .exception .MQBrokerException ;
26
21
import org .apache .rocketmq .client .exception .MQClientException ;
27
22
import org .apache .rocketmq .client .producer .LocalTransactionState ;
28
23
import org .apache .rocketmq .client .producer .SendResult ;
24
+ import org .apache .rocketmq .client .producer .SendStatus ;
29
25
import org .apache .rocketmq .client .producer .TransactionListener ;
30
26
import org .apache .rocketmq .client .producer .TransactionMQProducer ;
31
27
import org .apache .rocketmq .common .message .Message ;
34
30
import org .apache .rocketmq .common .message .MessageExt ;
35
31
import org .apache .rocketmq .remoting .RPCHook ;
36
32
import org .apache .rocketmq .remoting .exception .RemotingException ;
33
+ import org .apache .seata .common .util .StringUtils ;
34
+ import org .apache .seata .core .context .RootContext ;
35
+ import org .apache .seata .core .model .GlobalStatus ;
36
+ import org .apache .seata .rm .DefaultResourceManager ;
37
37
import org .slf4j .Logger ;
38
38
import org .slf4j .LoggerFactory ;
39
39
@@ -47,8 +47,10 @@ public class SeataMQProducer extends TransactionMQProducer {
47
47
48
48
private static final Logger LOGGER = LoggerFactory .getLogger (SeataMQProducer .class );
49
49
50
- private static final List <GlobalStatus > COMMIT_STATUSES = Arrays .asList (GlobalStatus .Committed , GlobalStatus .Committing , GlobalStatus .CommitRetrying );
51
- private static final List <GlobalStatus > ROLLBACK_STATUSES = Arrays .asList (GlobalStatus .Rollbacked , GlobalStatus .Rollbacking , GlobalStatus .RollbackRetrying );
50
+ private static final List <GlobalStatus > COMMIT_STATUSES =
51
+ Arrays .asList (GlobalStatus .Committed , GlobalStatus .Committing , GlobalStatus .CommitRetrying );
52
+ private static final List <GlobalStatus > ROLLBACK_STATUSES =
53
+ Arrays .asList (GlobalStatus .Rollbacked , GlobalStatus .Rollbacking , GlobalStatus .RollbackRetrying );
52
54
53
55
public static String PROPERTY_SEATA_XID = RootContext .KEY_XID ;
54
56
public static String PROPERTY_SEATA_BRANCHID = RootContext .KEY_BRANCHID ;
@@ -75,7 +77,8 @@ public LocalTransactionState checkLocalTransaction(MessageExt msg) {
75
77
LOGGER .error ("msg has no xid, msgTransactionId: {}, msg will be rollback" , msg .getTransactionId ());
76
78
return LocalTransactionState .ROLLBACK_MESSAGE ;
77
79
}
78
- GlobalStatus globalStatus = DefaultResourceManager .get ().getGlobalStatus (SeataMQProducerFactory .ROCKET_BRANCH_TYPE , xid );
80
+ GlobalStatus globalStatus =
81
+ DefaultResourceManager .get ().getGlobalStatus (SeataMQProducerFactory .ROCKET_BRANCH_TYPE , xid );
79
82
if (COMMIT_STATUSES .contains (globalStatus )) {
80
83
return LocalTransactionState .COMMIT_MESSAGE ;
81
84
} else if (ROLLBACK_STATUSES .contains (globalStatus ) || GlobalStatus .isOnePhaseTimeout (globalStatus )) {
@@ -90,12 +93,14 @@ public LocalTransactionState checkLocalTransaction(MessageExt msg) {
90
93
}
91
94
92
95
@ Override
93
- public SendResult send (Message msg ) throws MQClientException , MQBrokerException , RemotingException , InterruptedException {
96
+ public SendResult send (Message msg )
97
+ throws MQClientException , MQBrokerException , RemotingException , InterruptedException {
94
98
return send (msg , this .getSendMsgTimeout ());
95
99
}
96
100
97
101
@ Override
98
- public SendResult send (Message msg , long timeout ) throws MQClientException , MQBrokerException , RemotingException , InterruptedException {
102
+ public SendResult send (Message msg , long timeout )
103
+ throws MQClientException , MQBrokerException , RemotingException , InterruptedException {
99
104
if (RootContext .inGlobalTransaction ()) {
100
105
if (tccRocketMQ == null ) {
101
106
throw new RuntimeException ("TCCRocketMQ is not initialized" );
@@ -106,7 +111,8 @@ public SendResult send(Message msg, long timeout) throws MQClientException, MQBr
106
111
}
107
112
}
108
113
109
- public SendResult doSendMessageInTransaction (final Message msg , long timeout , String xid , long branchId ) throws MQClientException {
114
+ public SendResult doSendMessageInTransaction (final Message msg , long timeout , String xid , long branchId )
115
+ throws MQClientException {
110
116
msg .setTopic (withNamespace (msg .getTopic ()));
111
117
if (msg .getDelayTimeLevel () != 0 ) {
112
118
MessageAccessor .clearProperty (msg , MessageConst .PROPERTY_DELAY_TIME_LEVEL );
@@ -119,7 +125,7 @@ public SendResult doSendMessageInTransaction(final Message msg, long timeout, St
119
125
MessageAccessor .putProperty (msg , PROPERTY_SEATA_XID , xid );
120
126
MessageAccessor .putProperty (msg , PROPERTY_SEATA_BRANCHID , String .valueOf (branchId ));
121
127
try {
122
- sendResult = super . send (msg , timeout );
128
+ sendResult = superSend (msg , timeout );
123
129
} catch (Exception e ) {
124
130
throw new MQClientException ("send message Exception" , e );
125
131
}
@@ -137,6 +143,10 @@ public SendResult doSendMessageInTransaction(final Message msg, long timeout, St
137
143
return sendResult ;
138
144
}
139
145
146
+ public SendResult superSend (Message msg , long timeout )
147
+ throws MQClientException , MQBrokerException , RemotingException , InterruptedException {
148
+ return super .send (msg , timeout );
149
+ }
140
150
141
151
@ Override
142
152
public TransactionListener getTransactionListener () {
0 commit comments