You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

rm_remoting.go 3.6 kB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package remoting
  18. import (
  19. "sync"
  20. )
  21. import (
  22. "github.com/seata/seata-go/pkg/common/log"
  23. "github.com/seata/seata-go/pkg/protocol/branch"
  24. "github.com/seata/seata-go/pkg/protocol/message"
  25. "github.com/seata/seata-go/pkg/protocol/resource"
  26. "github.com/seata/seata-go/pkg/remoting/getty"
  27. )
  28. var (
  29. rmRemoting *RMRemoting
  30. onceGettyRemoting = &sync.Once{}
  31. )
  32. func GetRMRemotingInstance() *RMRemoting {
  33. if rmRemoting == nil {
  34. onceGettyRemoting.Do(func() {
  35. rmRemoting = &RMRemoting{}
  36. })
  37. }
  38. return rmRemoting
  39. }
  40. // TODO
  41. type RMRemoting struct {
  42. }
  43. // Branch register long
  44. func (RMRemoting) BranchRegister(branchType branch.BranchType, resourceId, clientId, xid, applicationData, lockKeys string) (int64, error) {
  45. return 0, nil
  46. }
  47. // Branch report
  48. func (RMRemoting) BranchReport(branchType branch.BranchType, xid string, branchId int64, status branch.BranchStatus, applicationData string) error {
  49. return nil
  50. }
  51. // Lock query boolean
  52. func (RMRemoting) LockQuery(branchType branch.BranchType, resourceId, xid, lockKeys string) (bool, error) {
  53. return false, nil
  54. }
  55. func (r *RMRemoting) RegisterResource(resource resource.Resource) error {
  56. req := message.RegisterRMRequest{
  57. AbstractIdentifyRequest: message.AbstractIdentifyRequest{
  58. //todo replace with config
  59. Version: "1.4.2",
  60. ApplicationId: "tcc-sample",
  61. TransactionServiceGroup: "my_test_tx_group",
  62. },
  63. ResourceIds: resource.GetResourceId(),
  64. }
  65. res, err := getty.GetGettyRemotingClient().SendSyncRequest(req)
  66. if err != nil {
  67. log.Errorf("RegisterResourceManager error: {%#v}", err.Error())
  68. return err
  69. }
  70. if isRegisterSuccess(res) {
  71. r.onRegisterRMSuccess(res.(message.RegisterRMResponse))
  72. } else {
  73. r.onRegisterRMFailure(res.(message.RegisterRMResponse))
  74. }
  75. return nil
  76. }
  77. func isRegisterSuccess(response interface{}) bool {
  78. //if res, ok := response.(protocol.RegisterTMResponse); ok {
  79. // return res.Identified
  80. //} else if res, ok := response.(protocol.RegisterRMResponse); ok {
  81. // return res.Identified
  82. //}
  83. //return false
  84. if res, ok := response.(message.RegisterRMResponse); ok {
  85. return res.Identified
  86. }
  87. return false
  88. }
  89. func (r *RMRemoting) onRegisterRMSuccess(response message.RegisterRMResponse) {
  90. // TODO
  91. log.Infof("register RM success. response: %#v", response)
  92. }
  93. func (r *RMRemoting) onRegisterRMFailure(response message.RegisterRMResponse) {
  94. // TODO
  95. log.Infof("register RM failure. response: %#v", response)
  96. }
  97. func (r *RMRemoting) onRegisterTMSuccess(response message.RegisterTMResponse) {
  98. // TODO
  99. log.Infof("register TM success. response: %#v", response)
  100. }
  101. func (r *RMRemoting) onRegisterTMFailure(response message.RegisterTMResponse) {
  102. // TODO
  103. log.Infof("register TM failure. response: %#v", response)
  104. }

Go Implementation For Seata