Example #1
0
        /// <summary>
        /// 获取完整的http请求地址
        /// </summary>
        /// <param name="serviceName"></param>
        /// <param name="pathName"></param>
        /// <returns></returns>
        public static string GetHttpRequestUri(string serviceName, string pathName)
        {
            //从配置文件中找到servicename
            string realServiceName = ConfigManager.AppSettings(serviceName);

            ConsulServiceFinder serviceFinder = new ConsulServiceFinder();

            string serviceHost = serviceFinder.GetServiceHttpAddress(realServiceName);

            if (string.IsNullOrWhiteSpace(serviceHost))
            {
                throw new Exception("not find any service by name:" + serviceName);
            }

            string servicePath = ConfigManager.AppSettings(pathName);

            if (string.IsNullOrWhiteSpace(servicePath))
            {
                throw new Exception("not find any path by name:" + servicePath);
            }

            string uri = $"{serviceHost}/{servicePath}";

            return(uri);
        }
Example #2
0
 public ConsulServiceFinderTest()
 {
     _finder = new ConsulServiceFinder(
         new ConsulHostConfiguration
     {
         Host = "192.168.1.9",
         Port = 8500
     });
 }