CAICAIIs commented on code in PR #1054:
URL: 
https://github.com/apache/incubator-seata-go/pull/1054#discussion_r2873565035


##########
pkg/integration/rocketmq/tcc_rocketmq_action.go:
##########
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package rocketmq
+
+import (
+       "context"
+       "fmt"
+
+       "github.com/apache/rocketmq-client-go/v2/primitive"
+
+       "seata.apache.org/seata-go/v2/pkg/constant"
+       "seata.apache.org/seata-go/v2/pkg/tm"
+       "seata.apache.org/seata-go/v2/pkg/util/log"
+)
+
+type TCCRocketMQAction struct {
+       producer *SeataMQProducer
+}
+
+func NewTCCRocketMQAction(producer *SeataMQProducer) *TCCRocketMQAction {
+       return &TCCRocketMQAction{
+               producer: producer,
+       }
+}
+
+func (a *TCCRocketMQAction) GetActionName() string {
+       return ResourceIDTCCRocketMQ
+}
+
+func (a *TCCRocketMQAction) Prepare(ctx context.Context, params interface{}) 
(bool, error) {
+       msg, ok := params.(*primitive.Message)
+       if !ok {
+               return false, fmt.Errorf("params must be *primitive.Message, 
got %T", params)
+       }
+
+       bac := tm.GetBusinessActionContext(ctx)
+       if bac == nil {
+               return false, fmt.Errorf("BusinessActionContext not found in 
context")
+       }
+
+       xid := tm.GetXID(ctx)
+       if xid == "" {
+               return false, fmt.Errorf("XID not found in context")
+       }
+
+       msg.WithProperty(constant.PropertySeataXID, xid)
+       msg.WithProperty(constant.PropertySeataBranchId, fmt.Sprintf("%d", 
bac.BranchId))
+
+       result, err := 
a.producer.transactionProducer.SendMessageInTransaction(ctx, msg)
+       if err != nil {
+               log.Errorf("[TCCRocketMQ] Prepare failed, xid=%s, err=%v", xid, 
err)
+               return false, err
+       }
+
+       bac.ActionContext[ActionContextKeyMsgId] = result.MsgID
+       bac.ActionContext[ActionContextKeyOffsetMsgId] = result.OffsetMsgID
+       bac.ActionContext[ActionContextKeyQueueOffset] = result.QueueOffset
+       bac.ActionContext[ActionContextKeyTransactionId] = result.TransactionID
+       if result.MessageQueue != nil {
+               bac.ActionContext[ActionContextKeyQueueId] = 
result.MessageQueue.QueueId
+               bac.ActionContext[ActionContextKeyBrokerName] = 
result.MessageQueue.BrokerName
+       }
+
+       log.Infof("[TCCRocketMQ] Prepare success, xid=%s, branchId=%d, 
msgId=%s", xid, bac.BranchId, result.MsgID)
+
+       return true, nil
+}
+
+func (a *TCCRocketMQAction) Commit(ctx context.Context, bac 
*tm.BusinessActionContext) (bool, error) {

Review Comment:
   
当前采用的纯回查模式,TCC的Commit/Rollback不做操作,是因为实际的消息状态决策已经委托给RocketMQ的CheckLocalTransaction回调,该回调通过查询Seata
 TC获取权威的全局事务状态。(依赖Broker回查间隔,适合mvp验证)
   而预计下一个pr会用主动通知模式改进这个问题,这时候将会和java那边达成一致



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to