Copilot commented on code in PR #798: URL: https://github.com/apache/incubator-seata-go/pull/798#discussion_r2094676737
########## pkg/integration/rocketmq/tcc_rocketmq_impl.go: ########## @@ -0,0 +1,119 @@ +/* + * 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" + "errors" + "github.com/apache/rocketmq-client-go/v2/primitive" + "seata.apache.org/seata-go/pkg/tm" + "seata.apache.org/seata-go/pkg/util/log" + "strings" +) + +type TCCRocketMQImpl struct { + producer *MQProducer +} + +func NewTCCRocketMQImpl() *TCCRocketMQImpl { + return &TCCRocketMQImpl{} +} + +func (t *TCCRocketMQImpl) SetProducer(producer *MQProducer) { + t.producer = producer +} + +func (t *TCCRocketMQImpl) Prepare(ctx context.Context, msg *primitive.Message) (*primitive.SendResult, error) { + businessActionCtx := tm.GetBusinessActionContext(ctx) + if businessActionCtx == nil { + return nil, errors.New("business action context not found") + } + + result, err := t.producer.SendMsgInTransaction(msg, businessActionCtx.Xid, businessActionCtx.BranchId) + if err != nil { + log.Errorf("Failed to send transaction message: %v", err) + return nil, err + } + + t.saveToActionContext(businessActionCtx, msg, result) + return result, nil +} + +func (t *TCCRocketMQImpl) Commit(ctx tm.BusinessActionContext) (bool, error) { + msg, result, err := t.getMessageAndResult(ctx) + if err != nil { + return false, err + } + + if err := t.validateMessage(msg, result); err != nil { + return false, err + } + + // TODO: implement rocketmq wrapper to support commit + log.Info("TCCRocketMQ message commit success xid = ", ctx.Xid, ", branchID = ", ctx.BranchId) + return true, nil +} + +func (t *TCCRocketMQImpl) Rollback(ctx tm.BusinessActionContext) (bool, error) { + msg, result, err := t.getMessageAndResult(ctx) + if err != nil { + log.Error("TCCRocketMQ message rollback: failed to get message or result") + return true, nil + } + + if err := t.validateMessage(msg, result); err != nil { + log.Error("TCCRocketMQ message rollback: invalid message or result") + return true, nil + } + + // TODO: implement rocketmq wrapper to support rollback Review Comment: Rollback operation is not fully implemented. Please add the necessary implementation or update the documentation to clearly state the current support limitations for transactional rollback. ########## pkg/integration/rocketmq/tcc_rocketmq_impl.go: ########## @@ -0,0 +1,119 @@ +/* + * 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" + "errors" + "github.com/apache/rocketmq-client-go/v2/primitive" + "seata.apache.org/seata-go/pkg/tm" + "seata.apache.org/seata-go/pkg/util/log" + "strings" +) + +type TCCRocketMQImpl struct { + producer *MQProducer +} + +func NewTCCRocketMQImpl() *TCCRocketMQImpl { + return &TCCRocketMQImpl{} +} + +func (t *TCCRocketMQImpl) SetProducer(producer *MQProducer) { + t.producer = producer +} + +func (t *TCCRocketMQImpl) Prepare(ctx context.Context, msg *primitive.Message) (*primitive.SendResult, error) { + businessActionCtx := tm.GetBusinessActionContext(ctx) + if businessActionCtx == nil { + return nil, errors.New("business action context not found") + } + + result, err := t.producer.SendMsgInTransaction(msg, businessActionCtx.Xid, businessActionCtx.BranchId) + if err != nil { + log.Errorf("Failed to send transaction message: %v", err) + return nil, err + } + + t.saveToActionContext(businessActionCtx, msg, result) + return result, nil +} + +func (t *TCCRocketMQImpl) Commit(ctx tm.BusinessActionContext) (bool, error) { + msg, result, err := t.getMessageAndResult(ctx) + if err != nil { + return false, err + } + + if err := t.validateMessage(msg, result); err != nil { + return false, err + } + + // TODO: implement rocketmq wrapper to support commit Review Comment: Commit operation is not fully implemented. Please ensure that a complete implementation or detailed documentation about the intended behavior is provided before production use. -- 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: notifications-unsubscr...@seata.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@seata.apache.org For additional commands, e-mail: notifications-h...@seata.apache.org