Example #1
0
        public string GetProfileContent(string profileServiceName, string application, string profile)
        {
            var invoker = new ProfileInvoker <string>((i, node, path) =>
            {
                string url   = i.JoinURL(node, path);
                string query = $"?application={application}&profile={profile}";
                try
                {
                    var result = HttpRequestClient.Request(url + query, "GET", false).Send().GetBodyContent(true);
                    return(result);
                }
                catch (Exception e)
                {
                    LogManager.Error("GetProfileContent error", e.Message);
                }
                return(string.Empty);
            });

            var context = new InvokerContext(
                new DirectoryContext("Profile/Pull", profileServiceName),
                new ClusterContext(FailoverCluster.NAME),
                new LoadBalanceContext(RandomLoadBalance.NAME));

            return(ClientInvoker.Invoke(invoker, context));
        }
Example #2
0
        public virtual ResultWithData <string> SayHello(string name, int age, InvokerContext context = null)
        {
            var actualContext = context as ServiceInvokerContext;

            var foodInvoker = new DemoInvoker <ResultWithData <string> >((invoker, node, path) =>
            {
                LogManager.Info("==test==", JsonConvert.SerializeObject(node));

                string url  = invoker.JoinURL(node, path) + "?name=" + name + "&age=" + age;
                var request = HttpRequestClient.Request(url, "GET", false);
                request.Headers.Add("SystemId", actualContext.SystemId);
                request.Headers.Add("Version", actualContext.Version);
                return(request.Send()
                       .GetBodyContent <ResultWithData <string> >(close: true));
            });

            return(ClientInvoker.Invoke(foodInvoker, context));
        }