Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

pirms 3 nedēļām
pirms 3 nedēļām
pirms 3 nedēļām
pirms 3 nedēļām
pirms 3 nedēļām
pirms 3 nedēļām
pirms 3 nedēļām
pirms 6 dienas
pirms 2 nedēļām
pirms 6 dienas
pirms 3 nedēļām
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package rpc
  2. import (
  3. "context"
  4. "egg-im/pkg/grpclib/picker"
  5. "egg-im/pkg/grpclib/resolver/k8s"
  6. "egg-im/pkg/pb"
  7. "fmt"
  8. "google.golang.org/grpc/balancer/roundrobin"
  9. "google.golang.org/grpc"
  10. )
  11. var (
  12. logicIntClient pb.LogicIntClient
  13. connectIntClient pb.ConnectIntClient
  14. businessIntClient pb.BusinessIntClient
  15. )
  16. func GetLogicIntClient() pb.LogicIntClient {
  17. if logicIntClient == nil {
  18. initLogicIntClient()
  19. }
  20. return logicIntClient
  21. }
  22. func GetConnectIntClient() pb.ConnectIntClient {
  23. if connectIntClient == nil {
  24. initConnectIntClient()
  25. }
  26. return connectIntClient
  27. }
  28. func GetBusinessIntClient() pb.BusinessIntClient {
  29. if businessIntClient == nil {
  30. initBusinessIntClient()
  31. }
  32. return businessIntClient
  33. }
  34. func initLogicIntClient() {
  35. conn, err := grpc.DialContext(context.TODO(), k8s.GetK8STarget("egg-im", "logic", "8000"), grpc.WithInsecure(),
  36. grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, roundrobin.Name)))
  37. if err != nil {
  38. panic(err)
  39. }
  40. logicIntClient = pb.NewLogicIntClient(conn)
  41. }
  42. func initConnectIntClient() {
  43. conn, err := grpc.DialContext(context.TODO(), k8s.GetK8STarget("egg-im", "connect", "8000"), grpc.WithInsecure(),
  44. grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, picker.AddrPickerName)))
  45. if err != nil {
  46. panic(err)
  47. }
  48. connectIntClient = pb.NewConnectIntClient(conn)
  49. }
  50. func initBusinessIntClient() {
  51. conn, err := grpc.DialContext(context.TODO(), "127.0.0.1:8000", grpc.WithInsecure(),
  52. grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, roundrobin.Name)))
  53. //conn, err := grpc.DialContext(context.TODO(), k8s.GetK8STarget("egg-im", "business", "8000"), grpc.WithInsecure(),
  54. // grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, roundrobin.Name)))
  55. if err != nil {
  56. panic(err)
  57. }
  58. businessIntClient = pb.NewBusinessIntClient(conn)
  59. }