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.

server.go 2.2 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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
  18. import (
  19. "fmt"
  20. "os"
  21. "os/signal"
  22. "syscall"
  23. "time"
  24. "dubbo.apache.org/dubbo-go/v3/config"
  25. _ "dubbo.apache.org/dubbo-go/v3/imports"
  26. "github.com/seata/seata-go/pkg/client"
  27. "github.com/seata/seata-go/pkg/common/log"
  28. "github.com/seata/seata-go/pkg/rm/tcc"
  29. "github.com/seata/seata-go/sample/tcc/dubbo/server/service"
  30. )
  31. // need to setup environment variable "DUBBO_GO_CONFIG_PATH" to "conf/dubbogo.yml" before run
  32. func main() {
  33. client.Init()
  34. userProviderProxy, err := tcc.NewTCCServiceProxy(&service.UserProvider{})
  35. if err != nil {
  36. log.Errorf("get userProviderProxy tcc service proxy error, %v", err.Error())
  37. return
  38. }
  39. config.SetProviderService(userProviderProxy)
  40. if err := config.Load(); err != nil {
  41. panic(err)
  42. }
  43. initSignal()
  44. }
  45. func initSignal() {
  46. signals := make(chan os.Signal, 1)
  47. // It is not possible to block SIGKILL or syscall.SIGSTOP
  48. signal.Notify(signals, os.Interrupt, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  49. for {
  50. sig := <-signals
  51. log.Infof("get signal %s", sig.String())
  52. switch sig {
  53. case syscall.SIGHUP:
  54. // reload()
  55. default:
  56. time.AfterFunc(time.Duration(int(3e9)), func() {
  57. log.Warnf("app exit now by force...")
  58. os.Exit(1)
  59. })
  60. // The program exits normally or timeout forcibly exits.
  61. fmt.Println("provider app exit now...")
  62. return
  63. }
  64. }
  65. }