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.

main.go 2.1 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 main implements a business for Greeter service.
  18. package main
  19. import (
  20. "fmt"
  21. "net"
  22. "google.golang.org/grpc"
  23. "github.com/seata/seata-go/pkg/client"
  24. grpc2 "github.com/seata/seata-go/pkg/integration/grpc"
  25. "github.com/seata/seata-go/pkg/rm/tcc"
  26. "github.com/seata/seata-go/pkg/util/log"
  27. "github.com/seata/seata-go/sample/tcc/grpc/pb"
  28. "github.com/seata/seata-go/sample/tcc/grpc/service"
  29. )
  30. func main() {
  31. client.InitPath("./sample/conf/seatago.yml")
  32. lis, err := net.Listen("tcp", fmt.Sprintf(":%d", 50051))
  33. if err != nil {
  34. log.Fatalf("failed to listen: %v", err)
  35. }
  36. log.Infof("server register")
  37. s := grpc.NewServer(grpc.UnaryInterceptor(grpc2.ServerTransactionInterceptor))
  38. b1 := &service.Business1{}
  39. b2 := &service.Business2{}
  40. proxy1, err := tcc.NewTCCServiceProxy(b1)
  41. if err != nil {
  42. log.Fatalf(err.Error())
  43. return
  44. }
  45. proxy2, err := tcc.NewTCCServiceProxy(b2)
  46. if err != nil {
  47. log.Fatalf(err.Error())
  48. return
  49. }
  50. pb.RegisterTCCServiceBusiness1Server(s, &service.GrpcBusinessService1{Business1: proxy1})
  51. pb.RegisterTCCServiceBusiness2Server(s, &service.GrpcBusinessService2{Business2: proxy2})
  52. log.Infof("business listening at %v", lis.Addr())
  53. if err := s.Serve(lis); err != nil {
  54. log.Fatalf("failed to serve: %v", err)
  55. }
  56. }