🔥A cross-language distributed transaction manager. Support xa, tcc, saga, transactional messages. 跨语言分布式事务管理器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

42 lines
1.1 KiB

/*
* Copyright (c) 2021 yedf. All rights reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*/
package dtmgrpc
import (
"github.com/yedf/dtm/dtmcli"
"github.com/yedf/dtm/dtmcli/dtmimp"
"github.com/yedf/dtm/dtmgrpc/dtmgimp"
"google.golang.org/protobuf/proto"
)
// MsgGrpc reliable msg type
type MsgGrpc struct {
dtmcli.Msg
}
// NewMsgGrpc create new msg
func NewMsgGrpc(server string, gid string) *MsgGrpc {
return &MsgGrpc{Msg: *dtmcli.NewMsg(server, gid)}
}
// Add add a new step
func (s *MsgGrpc) Add(action string, msg proto.Message) *MsgGrpc {
s.Steps = append(s.Steps, map[string]string{"action": action})
s.BinPayloads = append(s.BinPayloads, dtmgimp.MustProtoMarshal(msg))
return s
}
// Prepare prepare the msg, msg will later be submitted
func (s *MsgGrpc) Prepare(queryPrepared string) error {
s.QueryPrepared = dtmimp.OrString(queryPrepared, s.QueryPrepared)
return dtmgimp.DtmGrpcCall(&s.TransBase, "Prepare")
}
// Submit submit the msg
func (s *MsgGrpc) Submit() error {
return dtmgimp.DtmGrpcCall(&s.TransBase, "Submit")
}