ClusterTopClient.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using Top.Api.Cluster;
  2. namespace Top.Api
  3. {
  4. /// <summary>
  5. /// 异地多活自动分配集群客户端。
  6. /// </summary>
  7. public class ClusterTopClient : DefaultTopClient
  8. {
  9. public ClusterTopClient(string serverUrl, string appKey, string appSecret)
  10. : base(serverUrl, appKey, appSecret)
  11. {
  12. ClusterManager.InitRefreshThread(this);
  13. }
  14. public ClusterTopClient(string serverUrl, string appKey, string appSecret, string format)
  15. : base(serverUrl, appKey, appSecret, format)
  16. {
  17. ClusterManager.InitRefreshThread(this);
  18. }
  19. internal override string GetServerUrl(string serverUrl, string apiName, string session)
  20. {
  21. DnsConfig dnsConfig = ClusterManager.GetDnsConfigFromCache();
  22. if (dnsConfig == null)
  23. {
  24. return serverUrl;
  25. }
  26. else
  27. {
  28. return dnsConfig.GetBestVipUrl(serverUrl, apiName, session);
  29. }
  30. }
  31. internal override string GetSdkVersion()
  32. {
  33. return Constants.SDK_VERSION_CLUSTER;
  34. }
  35. }
  36. }