init.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package export
  2. import (
  3. "fmt"
  4. "os"
  5. "time"
  6. "gd_crontab/common.in/config"
  7. "github.com/smallnest/rpcx/client"
  8. "github.com/smallnest/rpcx/protocol"
  9. "github.com/smallnest/rpcx/share"
  10. )
  11. var xcli client.XClient
  12. func init() {
  13. // 先行于读配置
  14. //clinit.InitEtcd(etcdAddrs)
  15. conf := config.GetConfigForK8s()
  16. if conf == nil {
  17. fmt.Printf("get conf failed\n\n")
  18. os.Exit(1)
  19. }
  20. /*opt := client.Option{
  21. Retries: 1,
  22. RPCPath: share.DefaultRPCPath,
  23. ConnectTimeout: 10 * time.Second,
  24. SerializeType: protocol.JSON,
  25. CompressType: protocol.None,
  26. BackupLatency: 10 * time.Millisecond,
  27. }
  28. d := client.NewEtcdDiscovery(conf.Rpc.BasePath, conf.Rpc.Management.Name, etcdAddrs, nil)
  29. xcli = client.NewXClient(conf.Rpc.Management.Name, client.Failtry, client.RandomSelect, d, opt)
  30. */
  31. opt := client.Option{
  32. Retries: 1,
  33. RPCPath: share.DefaultRPCPath,
  34. ConnectTimeout: 10 * time.Second,
  35. SerializeType: protocol.JSON,
  36. CompressType: protocol.None,
  37. BackupLatency: 10 * time.Millisecond,
  38. }
  39. sd := client.NewPeer2PeerDiscovery(fmt.Sprintf("tcp@%s:%s", conf.Rpc.Crontab.ServiceName, conf.Rpc.Crontab.ServicePort.String()), "")
  40. xcli = client.NewXClient(conf.Rpc.Crontab.Name, client.Failtry, client.RandomSelect, sd, opt)
  41. }