Beispiel #1
0
        public ClientsDispatcher(IWebSocketConnectionManager manager, IBackplane backplane, ILogger <ClientsDispatcher> logger)
        {
            Manager   = manager;
            Backplane = backplane;
            _logger   = logger;

            All = new ClientInvoker(
                async(methodName, args) =>
            {
                var message = new Message()
                {
                    MessageType = MessageType.ClientMethodInvocation,
                    Data        = MessageSerializer.SerializeObject(new InvocationDescriptor()
                    {
                        MethodName = methodName,
                        Arguments  = args
                    })
                };
                await Backplane.SendMessageAllAsync(message).ConfigureAwait(false);
            },
                async msg =>
            {
                await Backplane.SendMessageAllAsync(msg).ConfigureAwait(false);
            },
                async group => {
                await Backplane.SubscribeAll(group).ConfigureAwait(false);
            },
                async group => {
                await Backplane.UnsubscribeAll(group).ConfigureAwait(false);
            });
        }
Beispiel #2
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));
        }
Beispiel #3
0
        /// <summary>
        /// sync call Demo1
        /// </summary>
        /// <returns>result</returns>
        private static string Demo1()
        {
            //Init Client
            var client1 = new ClientInvoker<IService1, Service1Client>(); // Config: GlobalAssemblyConfig -> DemoServiceClient.exe.config

            //invoke Request
            var data = string.Empty;
            var result = client1.InvokeRequest(
                (clientBase) =>
                {
                    data = clientBase.GetData(1);

                    return !string.IsNullOrWhiteSpace(data);
                });

            return "Demo1() => " + nameof(result) + " -> " + result + " | " + nameof(data) + " -> " + data;
        }
Beispiel #4
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));
        }
Beispiel #5
0
        /// <summary>
        /// async call Demo2
        /// </summary>
        /// <returns>result</returns>
        private static string Demo2()
        {
            //Init Client
            var client2 = new ClientInvoker<IService2, Service2Client>(); // Config: AssemblyConfig -> DemoServiceContract.dll.config

            //invoke Async Request
            var dataAsync = string.Empty;
            var resultAsync = client2.InvokeRequestAsync(
                async (clientBase) =>
                {
                    dataAsync = await clientBase.GetData2Async(2);

                    return !string.IsNullOrWhiteSpace(dataAsync);
                });
            resultAsync.Wait();

            return "Demo2() => " + nameof(resultAsync) + " -> " + resultAsync.Result + " | " + nameof(dataAsync) + " -> " + dataAsync;
        }
Beispiel #6
0
        /// <summary>
        /// async call Demo2
        /// </summary>
        /// <returns>result</returns>
        private static string Demo4()
        {
            //Init Client
            var client4 = new ClientInvoker<ServiceClient.ServiceReferenceDemo4.IService1, Service1ClientDemo4>(); // Config: GlobalAssemblyConfig -> DemoServiceClient.exe.config    over static/const field/property called 'DefaultEndpointConfigurationName'

            //invoke Async Request
            var dataAsync = string.Empty;
            var resultAsync = client4.InvokeRequestAsync(
                async (clientBase) =>
                {
                    dataAsync = await clientBase.GetDataAsync(4);

                    return !string.IsNullOrWhiteSpace(dataAsync);
                });
            resultAsync.Wait();

            return "Demo4() => " + nameof(resultAsync) + " -> " + resultAsync.Result + " | " + nameof(dataAsync) + " -> " + dataAsync;
        }