Skip to content

Commit

Permalink
use config (apache#436)
Browse files Browse the repository at this point in the history
* fix bug
  • Loading branch information
luky116 authored and georgehao committed May 7, 2023
1 parent 28cf354 commit bbd483b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
5 changes: 5 additions & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/seata/seata-go/pkg/integration"
"github.com/seata/seata-go/pkg/remoting/getty"
"github.com/seata/seata-go/pkg/remoting/processor/client"
"github.com/seata/seata-go/pkg/rm"
"github.com/seata/seata-go/pkg/rm/tcc"
"github.com/seata/seata-go/pkg/tm"
"github.com/seata/seata-go/pkg/util/log"
Expand Down Expand Up @@ -69,6 +70,10 @@ func initRmClient(cfg *Config) {
onceInitRmClient.Do(func() {
log.Init()
initRemoting(cfg)
rm.InitRm(rm.RmConfig{
ApplicationID: cfg.ApplicationID,
TxServiceGroup: cfg.TxServiceGroup,
})
client.RegisterProcessor()
integration.Init()
tcc.InitTCC()
Expand Down
1 change: 1 addition & 0 deletions pkg/remoting/getty/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func (cfg *TransportConfig) RegisterFlagsWithPrefix(prefix string, f *flag.FlagS
f.DurationVar(&cfg.RPCTmRequestTimeout, prefix+".rpc-tm-request-timeout", 30*time.Second, "TM send request timeout.")
}

// todo refactor config
type SeataConfig struct {
ApplicationID string
TxServiceGroup string
Expand Down
2 changes: 1 addition & 1 deletion pkg/remoting/getty/rpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,6 @@ func (c *RpcClient) setSessionConfig(session getty.Session) {
session.SetEventListener(GetGettyClientHandlerInstance())
session.SetReadTimeout(c.gettyConf.SessionConfig.TCPReadTimeout)
session.SetWriteTimeout(c.gettyConf.SessionConfig.TCPWriteTimeout)
session.SetCronPeriod((int)(c.gettyConf.SessionConfig.CronPeriod.Nanoseconds() / 1e6))
session.SetCronPeriod((int)(c.gettyConf.SessionConfig.CronPeriod.Milliseconds()))
session.SetWaitTime(c.gettyConf.SessionConfig.WaitTimeout)
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (f *rmBranchRollbackProcessor) Process(ctx context.Context, rpcMessage mess
log.Errorf("branch rollback error: %s", err.Error())
return err
}
log.Infof("branch rollback success: xid %s, branchID %s, resourceID %s, applicationData %s", xid, branchID, resourceID, applicationData)
log.Infof("branch rollback success: xid %s, branchID %d, resourceID %s, applicationData %s", xid, branchID, resourceID, applicationData)

var (
resultCode message.ResultCode
Expand Down
11 changes: 7 additions & 4 deletions pkg/rm/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@

package rm

// Init init seata client
func Init() {
initRmClient()
var rmConfig RmConfig

type RmConfig struct {
ApplicationID string
TxServiceGroup string
}

// InitRmClient init seata rm client
func initRmClient() {
func InitRm(cfg RmConfig) {
rmConfig = cfg
}
5 changes: 2 additions & 3 deletions pkg/rm/rm_remoting.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,9 @@ func (r *RMRemoting) LockQuery(param LockQueryParam) (bool, error) {
func (r *RMRemoting) RegisterResource(resource Resource) error {
req := message.RegisterRMRequest{
AbstractIdentifyRequest: message.AbstractIdentifyRequest{
// todo replace with config
Version: "1.5.2",
ApplicationId: "tcc-sample",
TransactionServiceGroup: "my_test_tx_group",
ApplicationId: rmConfig.ApplicationID,
TransactionServiceGroup: rmConfig.TxServiceGroup,
},
ResourceIds: resource.GetResourceId(),
}
Expand Down

0 comments on commit bbd483b

Please sign in to comment.