示例#1
0
        private static async Task RabbitMQ()
        {
            //RabbitMQ
            Console.WriteLine("\r\n--------------- Client RabbitMQ ---------------");
            var services = new ServiceCollection();

            services.AddNClientContract <IServiceAsync>();
            services.AddNClientContract <IService>();
            services.AddNRabbitMQClient(o => o.CopyFrom(Helper.GetMQOptions()));
            var sp = services.BuildServiceProvider();

            _clientProxy                   = sp.GetService <IClientProxy <IService> >();
            _clientProxy.Connected        += (_, _) => Console.WriteLine("[event] Connected");
            _clientProxy.DisConnected     += (_, _) => Console.WriteLine("[event] DisConnected");
            _clientProxy.ExceptionInvoked += (_, _) => Console.WriteLine("[event] ExceptionInvoked");

            //Heartbeat
            _clientProxy.HeartbeatAsync += (s, e) =>
            {
                Console.WriteLine("[event] Heartbeat");
                ((IService)((IClientProxy)s).Proxy).Hearbeat();
                return(Task.CompletedTask);
            };
            //clientProxy.StartHeartbeat(true);

            _proxy      = _clientProxy.Proxy;
            _proxyAsync = sp.GetService <IClientProxy <IServiceAsync> >() !.Proxy;
            RunTest();
            await RunTestAsync();
        }
示例#2
0
        private static async Task Main(string[] args)
        {
            var services = new ServiceCollection();

            services.AddNClientContract <IServiceAsync>();
            services.AddNHttpClient(o =>
            {
                o.SignalRHubUrl = "http://localhost:5000/callback";
                o.ApiUrl        = "http://localhost:5000/api";
            });
            var sp = services.BuildServiceProvider();

            _proxyAsync = sp.GetService <IServiceAsync>();

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

            Console.WriteLine("test end");
            Console.Read();
        }
示例#3
0
        private static async Task Grpc()
        {
            Console.WriteLine("\r\n--------------- Client Grpc ---------------");
            var services = new ServiceCollection();

            services.AddNClientContract <IServiceAsync>();
            services.AddNClientContract <IService>();
            services.AddNGrpcClient(o => o.Url = "http://localhost:50001");
            var sp = services.BuildServiceProvider();

            _clientProxy = sp.GetService <IClientProxy <IService> >();
            _proxy       = _clientProxy.Proxy;
            _proxyAsync  = sp.GetService <IClientProxy <IServiceAsync> >() !.Proxy;
            RunTest();
            await RunTestAsync();
        }
示例#4
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();
        }
示例#5
0
        static async Task Main(string[] args)
        {
            //RabbitMQ
            Console.WriteLine("--- Client RabbitMQ  ---");
            var mqF = new RabbitMQClientConnectionFactoryOptions(Helper.GetMQOptions(), NullLoggerFactory.Instance);

            _clientProxy                   = NManager.CreateClientProxy <IService>(mqF);
            _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.HeartbeatAsync += (s, e) =>
            {
                Console.WriteLine("[event] Heartbeat");
                ((IService)((IClientProxy)s).Proxy).Hearbeat();
                return(Task.CompletedTask);
            };
            //clientProxy.StartHeartbeat(true);

            _proxy      = _clientProxy.Proxy;
            _proxyAsync = NManager.CreateClientProxy <IServiceAsync>(mqF).Proxy;
            RunTest();
            await RunTestAsync();

            //Grpc
            Console.WriteLine("\r\n--- Client Grpc  ---");
            var grpcF = new GrpcClientConnectionFactoryOptions(
                new GrpcClientOptions {
                Host = "localhost", Port = 50001
            });

            _clientProxy = NetRpc.Grpc.NManager.CreateClientProxy <IService>(grpcF);
            _proxy       = _clientProxy.Proxy;
            _proxyAsync  = NetRpc.Grpc.NManager.CreateClientProxy <IServiceAsync>(grpcF).Proxy;

            RunTest();
            await RunTestAsync();

            Console.WriteLine("Test end.");
            Console.Read();
        }
示例#6
0
        private static async Task Http()
        {
            Console.WriteLine("\r\n--------------- Client Http ---------------");
            var services = new ServiceCollection();

            services.AddNClientContract <IService>();
            services.AddNClientContract <IServiceAsync>();
            services.AddNHttpClient(o =>
            {
                o.SignalRHubUrl = "http://localhost:50002/callback";
                o.ApiUrl        = "http://localhost:50002/api";
            });
            var sp = services.BuildServiceProvider();

            _clientProxy = sp.GetService <IClientProxy <IService> >();
            _proxy       = _clientProxy.Proxy;
            _proxyAsync  = sp.GetService <IClientProxy <IServiceAsync> >() !.Proxy;
            RunTest();
            await RunTestAsync();
        }
示例#7
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();
        }
 /// <summary>
 /// Close connection and delete proxy.
 /// </summary>
 private void Disconnect_Click(object sender, RoutedEventArgs e) {
     if(mProxy == null) {
         this.Output("Not connected.");
         return;
     }
     try {
         this.Output("Disconnecting...");
         this.ClientChannel.Close();
     } catch {
         this.ClientChannel.Abort();
     } finally {
         this.Output("Disconnected.");
         mProxy = null;
     }
 }
 /// <summary>
 /// Connect to the server.
 /// </summary>
 private void Connect_Click(object sender, RoutedEventArgs e) {
     if(mProxy != null) {
         this.Output("Already connected.");
         return;
     }
     try {
         this.Output("Connecting...");
         mProxy = mFactory.CreateChannel();
         this.ClientChannel.Open();
         this.Output("Connected.");
     } catch(Exception ex) {
         this.Output("Failed to connect: {0}", ex);
         if(mProxy != null) {
             this.ClientChannel.Abort();
         }
         mProxy = null;
     }
 }