Exemplo n.º 1
0
        static async Task Main(string[] args)
        {
            var p = NetRpcManager.CreateClientProxy <IService>(new GrpcClientOptions {
                Host = "localhost", Port = 50001
            });
            await p.Proxy.Call(async i => Console.WriteLine($"receive callback: {i}"));

            Console.Read();
        }
Exemplo n.º 2
0
        static async Task Main(string[] args)
        {
            var p = NetRpcManager.CreateClientProxy <IService>(new GrpcClientOptions
            {
                Host = "lj",
                Port = 50001
            });
            await p.Proxy.Call("hello world.");

            Console.Read();
        }
Exemplo n.º 3
0
        static async Task Main(string[] args)
        {
            //var c = NetRpcManager.CreateClientProxy<ITranslateRawService>(new GrpcClientOptions() {Url = "http://m.k8s.yx.com:34418"});
            var c = NetRpcManager.CreateClientProxy <ITranslateRawService>(new GrpcClientOptions()
            {
                Url = "http://localhost:8006"
            });

            var r = await c.Proxy.TranslateTextByEngineTypeAsync(new List <string>() { "hello" }, Guid.Empty, null, TranslateType.Chat,
                                                                 LanguageType.en, LanguageType.zs, null, null, default);

            Console.WriteLine("Hello World!");
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            var proxy      = NetRpcManager.CreateClientProxy <IService>(Helper.GetMQParam()).Proxy;
            var fileStream = File.Open(@"d:\4\1212.pdf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            for (int i = 0; i < 10; i++)
            {
                proxy.CallAsync(fileStream, j => Console.WriteLine(j), i.ToString());
                Console.WriteLine($"Send {i}");
            }

            Console.WriteLine($"Send end");
            Console.Read();
        }
Exemplo n.º 5
0
        static async Task Main(string[] args)
        {
            _proxyAsync = NetRpcManager.CreateClientProxy <IServiceAsync>(new HttpClientOptions
            {
                SignalRHubUrl = "http://localhost:5000/callback",
                ApiUrl        = "http://localhost:5000/api"
            }).Proxy;

            await Test_CallAsync();
            await Test_CallByCancelAsync();
            await Test_CallByCustomExceptionAsync();
            await Test_CallByDefaultExceptionAsync();
            await Test_CallByResponseTextExceptionAsync();
            await Test_ComplexCallAsync();

            Console.Read();
        }
Exemplo n.º 6
0
        static async Task Main(string[] args)
        {
            HttpClient c   = new HttpClient();
            var        res = await c.GetAsync("http://localhost:5000/11");

            //var p = NetRpcManager.CreateClientProxy<IService>(new Channel("localhost", 5000, ChannelCredentials.Insecure));
            var p = NetRpcManager.CreateClientProxy <IService>(new GrpcClientOptions()
            {
                Host = "localhost", Port = 5001, PublicKey = PublicKey
            });
            //await p.Proxy.Call("hello world.");

            var channel = new Channel("localhost", 5000, ChannelCredentials.Insecure);
            var client  = new Greeter.GreeterClient(channel);
            var r       = await client.SayHelloAsync(new HelloRequest()
            {
                Name = "n1"
            });

            Console.Read();
        }
Exemplo n.º 7
0
        static async Task Main(string[] args)
        {
            var proxy = NetRpcManager.CreateClientProxy <IServiceAsync>(Helper.GetMQOptions()).Proxy;

            for (var i = 0; i < 10; i++)
            {
                var i1 = i;
                Task.Run(async() =>
                {
                    Console.WriteLine($"Send {i1}");
                    await proxy.CallAsync(async p => Console.WriteLine(p), i1.ToString());
                });
            }

            //for (int i = 0; i < 10; i++)
            //{
            //    using (var stream = File.Open(Helper.GetTestFilePath(), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            //        await proxy.PostAsync(i.ToString(), stream);
            //    Console.WriteLine($"post {i}");
            //}

            Console.WriteLine("Send end");
            Console.Read();
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            //RabbitMQ
            Console.WriteLine("---  [RabbitMQ]  ---");
            var mqF         = new ClientConnectionFactory(Helper.GetMQParam());
            var clientProxy = NetRpcManager.CreateClientProxy <IService>(mqF, false);

            clientProxy.Connected        += (s, e) => Console.WriteLine("[event] Connected");
            clientProxy.DisConnected     += (s, e) => Console.WriteLine("[event] DisConnected");
            clientProxy.ExceptionInvoked += (s, e) => Console.WriteLine("[event] ExceptionInvoked");

            //Heartbeat
            clientProxy.Heartbeat += async s =>
            {
                Console.WriteLine("[event] Heartbeat");
                s.Proxy.Hearbeat();
            };
            clientProxy.StartHeartbeat(true);

            _proxy      = clientProxy.Proxy;
            _proxyAsync = NetRpcManager.CreateClientProxy <IServiceAsync>(mqF, false).Proxy;
            RunTest();
            RunTestAsync().Wait();

            //Grpc
            Console.WriteLine("\r\n--- [Grpc]  ---");
            var grpcF = new NetRpc.Grpc.ClientConnectionFactory(new Channel("localhost", 50001, ChannelCredentials.Insecure));

            _proxy      = NetRpc.Grpc.NetRpcManager.CreateClientProxy <IService>(grpcF).Proxy;
            _proxyAsync = NetRpc.Grpc.NetRpcManager.CreateClientProxy <IServiceAsync>(grpcF).Proxy;
            RunTest();
            RunTestAsync().Wait();

            Console.WriteLine("Test end.");
            Console.Read();
        }