client.go 883 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package client
  2. import (
  3. "bet24.com/log"
  4. "bet24.com/servers/micros/common"
  5. "context"
  6. rpcx_client "github.com/smallnest/rpcx/client"
  7. )
  8. var consulAddr = common.Default_Consul_Addr
  9. func getClient(serviceName string) rpcx_client.XClient {
  10. return common.GetClientPool().GetClient(serviceName, consulAddr)
  11. }
  12. func SetConsulAddr(addr string) {
  13. consulAddr = addr
  14. }
  15. type Reply struct {
  16. Data string
  17. RetCode int
  18. }
  19. type Request struct {
  20. UserId int
  21. Data string
  22. }
  23. func OnNotification(addr string, userId int, data string) bool {
  24. //log.Debug("OnNotification addr = %s", addr)
  25. xclient := getClient(addr)
  26. reply := &Reply{}
  27. err := xclient.Call(context.Background(), "OnNotification", &Request{UserId: userId, Data: data}, reply)
  28. if err != nil {
  29. log.Debug("OnNotification failed to call: %v", err)
  30. common.GetClientPool().RemoveClient(addr)
  31. return false
  32. }
  33. return true
  34. }