From 181c4923b47622d341b5b2b2124ec03fcadc76fc Mon Sep 17 00:00:00 2001 From: Yuecai Liu <38887641+luky116@users.noreply.github.com> Date: Tue, 3 Jan 2023 10:32:25 +0800 Subject: [PATCH] use config (#436) * fix bug --- pkg/client/client.go | 5 +++++ pkg/remoting/getty/config.go | 1 + pkg/remoting/getty/rpc_client.go | 2 +- .../processor/client/rm_branch_rollback_processor.go | 2 +- pkg/rm/init.go | 11 +++++++---- pkg/rm/rm_remoting.go | 5 ++--- 6 files changed, 17 insertions(+), 9 deletions(-) diff --git a/pkg/client/client.go b/pkg/client/client.go index 3b1e2433..718a30a8 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -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" @@ -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() diff --git a/pkg/remoting/getty/config.go b/pkg/remoting/getty/config.go index 78b93ad9..b85ce55f 100644 --- a/pkg/remoting/getty/config.go +++ b/pkg/remoting/getty/config.go @@ -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 diff --git a/pkg/remoting/getty/rpc_client.go b/pkg/remoting/getty/rpc_client.go index 4221b4d1..fca77136 100644 --- a/pkg/remoting/getty/rpc_client.go +++ b/pkg/remoting/getty/rpc_client.go @@ -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) } diff --git a/pkg/remoting/processor/client/rm_branch_rollback_processor.go b/pkg/remoting/processor/client/rm_branch_rollback_processor.go index 0a33d402..c1ff4ac1 100644 --- a/pkg/remoting/processor/client/rm_branch_rollback_processor.go +++ b/pkg/remoting/processor/client/rm_branch_rollback_processor.go @@ -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 diff --git a/pkg/rm/init.go b/pkg/rm/init.go index 43fd8796..dfccd05f 100644 --- a/pkg/rm/init.go +++ b/pkg/rm/init.go @@ -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 } diff --git a/pkg/rm/rm_remoting.go b/pkg/rm/rm_remoting.go index 54c3d807..87929846 100644 --- a/pkg/rm/rm_remoting.go +++ b/pkg/rm/rm_remoting.go @@ -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(), }