pb.go 949 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package proto
  2. import (
  3. "bet24.com/log"
  4. "bet24.com/servers/micros/common"
  5. "context"
  6. "github.com/smallnest/rpcx/client"
  7. )
  8. const ServiceName = "remotemessage"
  9. var consulAddr = common.Default_Consul_Addr
  10. func getClient() client.XClient {
  11. return common.GetClientPool().GetClient(ServiceName, consulAddr)
  12. }
  13. type Request struct {
  14. Name string
  15. UserId int
  16. DeviceType int
  17. Token string
  18. Title string
  19. Content string
  20. UserIds []int
  21. }
  22. type Response struct {
  23. Data string
  24. }
  25. func SetConsulAddr(addr string) {
  26. consulAddr = addr
  27. }
  28. func SayHello(name string) string {
  29. xclient := getClient()
  30. args := &Request{
  31. Name: name,
  32. }
  33. reply := &Response{}
  34. err := xclient.Call(context.Background(), "SayHello", args, reply)
  35. if err != nil {
  36. log.Debug("remotemessage failed to call: %v", err)
  37. common.GetClientPool().RemoveClient(ServiceName)
  38. return ""
  39. }
  40. log.Debug("SayHello return %s", reply.Data)
  41. return reply.Data
  42. }