コード例 #1
0
 public Task StopAsync(CancellationToken cancellationToken)
 {
     return(Task.Factory.StartNew(() =>
     {
         GrpcServiceManager.Stop();
     }, cancellationToken));
 }
コード例 #2
0
 public Task StartAsync(CancellationToken cancellationToken)
 {
     return(Task.Factory.StartNew(() =>
     {
         GrpcServiceManager.Start(GrpcExampleService.BindService(_grpcServiceBase), _tracer);
     }, cancellationToken));
 }
コード例 #3
0
        public Task StopAsync(CancellationToken cancellationToken)
        {
            return(Task.Factory.StartNew(() =>
            {
                GrpcServiceManager.Stop();

                _logger.LogInformation($"{typeof(HostedService).Namespace.Replace(".", "")}停止成功");
            }, cancellationToken));
        }
コード例 #4
0
        public Task StopAsync(CancellationToken cancellationToken)
        {
            return(Task.Factory.StartNew(() =>
            {
                GrpcServiceManager.Stop();

                _logger.LogError($"{nameof(Overt.GrpcTemplate.Service).Replace(".", "")}停止");
            }, cancellationToken));
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: bluexray/Horizon
        static async Task Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         //.WriteTo.Console()
                         .WriteTo.Console(
                outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")
                         .CreateLogger();


            await GrpcServiceManager.CallService("http://localhost:10042", async channel =>
            {
                var clinet = channel.CreateGrpcService <IStudentCollection>();


                var rs = await clinet.GetStudentAsync(new ResponeConext
                {
                    Name = "Peter"
                });

                Console.WriteLine($"学生学号: {rs.No}" + $"学生姓名: {rs.Name} " + $"学生性别: {rs.Age}");
                Console.ReadKey();
                return(rs);
            });

            #region 常规写法



            //GrpcClientFactory.AllowUnencryptedHttp2 = true;

            //AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);



            //using var http = GrpcChannel.ForAddress("http://localhost:10042");
            //var token = "";
            //var headers = new Metadata { { "Authorization", $"Bearer {token}" } };

            //var  service = http.CreateGrpcService<IStudentCollection>();


            ////using var cancel = new CancellationTokenSource(TimeSpan.FromMinutes(1));
            ////var options = new CallOptions(cancellationToken: cancel.Token);



            //var  result= await service.GetStudentAsync(new ResponeConext
            //{
            //    Name = "Tommy"
            //});

            //Console.WriteLine($"学生学号: {result.No}"+$"学生姓名: {result.Name} "+$"学生性别: {result.Age}");
            //Console.ReadKey();
            #endregion
        }
コード例 #6
0
ファイル: MainService.cs プロジェクト: zxzxzxzxzxtb/core-grpc
        public void Start(string serviceName)
        {
            // LogHelper.LogInfo($"{serviceName}服务启动");
            // autofac
            var container = AutofacContainer.Register();

            // grpc
            GrpcServiceManager.Start(GrpcExampleService.BindService(new GrpcExampleServiceImpl(container)), new ConsoleTracer(), whenException: (ex) =>
            {
            });
        }
コード例 #7
0
 public Task StartAsync(CancellationToken cancellationToken)
 {
     return(Task.Factory.StartNew(() =>
     {
         GrpcServiceManager.Start(GrpcExampleService.BindService(_grpcServiceBase), (grpcOptions) =>
         {
             grpcOptions.Tracer = _tracer;
             grpcOptions.GenServiceId = null;
         });
     }, cancellationToken));
 }
コード例 #8
0
 public Task StartAsync(CancellationToken cancellationToken)
 {
     return(Task.Factory.StartNew(() =>
     {
         var channelOptions = new List <ChannelOption>()
         {
             new ChannelOption(ChannelOptions.MaxReceiveMessageLength, int.MaxValue),
             new ChannelOption(ChannelOptions.MaxSendMessageLength, int.MaxValue),
         };
         GrpcServiceManager.Start(BindService(_grpcServImpl), channelOptions: channelOptions, whenException: (ex) =>
         {
             _logger.LogError(ex, $"{typeof(HostedService).Namespace.Replace(".", "")}开启失败");
             throw ex;
         });
         System.Console.WriteLine("服务已经启动");
         _logger.LogInformation($"{nameof(Jlion.NetCore.OrderService.Service).Replace(".", "")}开启成功");
     }, cancellationToken));
 }
コード例 #9
0
        public Task StartAsync(CancellationToken cancellationToken)
        {
            return(Task.Factory.StartNew(() =>
            {
                var channelOptions = new List <ChannelOption>()
                {
                    new ChannelOption(ChannelOptions.MaxReceiveMessageLength, int.MaxValue),
                    new ChannelOption(ChannelOptions.MaxSendMessageLength, int.MaxValue),
                };
                GrpcServiceManager.Start(BindService(_grpcServImpl), channelOptions: channelOptions, whenException: (ex) =>
                {
                    _logger.LogError($"{nameof(Overt.GrpcTemplate.Service).Replace(".", "")}服务器开启失败");
                    throw ex;
                });

                _logger.LogError($"{nameof(Overt.GrpcTemplate.Service).Replace(".", "")}开启");
            }, cancellationToken));
        }
コード例 #10
0
ファイル: MainService.cs プロジェクト: zhyfreefly/core-grpc
 public void ShutDown(string serviceName)
 {
     GrpcServiceManager.Stop();
     // LogHelper.LogInfo($"{serviceName}服务停止");
 }