예제 #1
0
        static async Task Main(string[] args)
        {
            var server = new G.Server
            {
                Services = { Generated.SampleService.BindService(new SampleServiceImplementation()) },
                Ports    = { new G.ServerPort("127.0.0.1", 5000, G.ServerCredentials.Insecure) }
            };

            server.Start();

            var t = Task.Run(async() =>
            {
                try
                {
                    await Task.Delay(1000);
                    var client = GrpcClientFactory.Create <Service.ISampleService>(new GrpcClientOptions {
                        Url = "127.0.0.1", Port = 5000
                    }, new ProtoBufSerializer());
                    var request = new Service.SampleRequest {
                        Value = 1
                    };
                    var response = await client.SendAsync(request, CancellationToken.None);
                    Console.WriteLine("{0} -> {1}", request.Value, response.Value);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            });

            await t;
            await server.ShutdownAsync();
        }
예제 #2
0
 internal GrpcWhen(GrpcClientFactory grpcClientFactory, EventAggregator eventAggregator, Api api,
                   LogWriter logWriter, Action preApiCall) : base(
         api, eventAggregator, logWriter, preApiCall)
 {
     _grpcClientFactory = grpcClientFactory;
     _eventAggregator   = eventAggregator;
 }
 public CartService(GrpcClientFactory grpcClientFactory, CartRepository cartRepository,
                    CartItemRepository cartItemRepository)
 {
     _grpcClientFactory  = grpcClientFactory;
     _cartRepository     = cartRepository;
     _cartItemRepository = cartItemRepository;
 }
예제 #4
0
        public static IHostClient CreateHostClient(this GrpcClientFactory factory, string name)
        {
            var clientName = ClientName.Host(name);
            var client     = factory.CreateClient <Host.HostClient>(clientName);

            return(new HostClientWrapper(client));
        }
예제 #5
0
        public static IFileSystemClient CreateFileSystemClient(this GrpcClientFactory factory, string name)
        {
            var clientName = ClientName.FileSystem(name);
            var client     = factory.CreateClient <FileSystem.FileSystemClient>(clientName);

            return(new FileSystemClientWrapper(client));
        }
예제 #6
0
 public CartsController(CartRepository cartRepository, CartItemRepository cartItemRepository,
                        CartService cartService, GrpcClientFactory grpcClientFactory)
 {
     _cartRepository     = cartRepository;
     _cartItemRepository = cartItemRepository;
     _cartService        = cartService;
     _grpcClientFactory  = grpcClientFactory;
 }
예제 #7
0
        public void Create_WithBaseAddress_ReturnInstance()
        {
            // Arrange & Act
            var client = GrpcClientFactory.Create <GreeterClient>("http://localhost");

            // Assert
            Assert.IsNotNull(client);
        }
 public ClientServiceConnector(GrpcClientFactory grpcClientFactory,
                               IClientQueuedRequests clientQueuedRequests,
                               IClientQueuedResponses clientQueuedResponses,
                               ILogger <ClientServiceConnector> logger)
 {
     _grpcClientFactory     = grpcClientFactory ?? throw new ArgumentNullException(nameof(grpcClientFactory));
     _clientQueuedRequests  = clientQueuedRequests ?? throw new ArgumentNullException(nameof(clientQueuedRequests));
     _clientQueuedResponses = clientQueuedResponses ?? throw new ArgumentNullException(nameof(clientQueuedResponses));
     _logger = logger ?? throw new ArgumentNullException(nameof(logger));
     _cancellationTokenSource = null;
 }
예제 #9
0
 private TClient CreateClient <TClient>(IChannel channel) where TClient : ClientBase <TClient>
 {
     if (channel is CoreChannel coreChannel)
     {
         return((TClient)Activator.CreateInstance(typeof(TClient), coreChannel.Channel));
     }
     else if (channel is HttpClientChannel httpClientChannel)
     {
         return(GrpcClientFactory.Create <TClient>($"http://{options.ServerHost}:{options.ServerPort}", certificate: null));
     }
     else
     {
         throw new Exception("Unexpected channel type.");
     }
 }
예제 #10
0
 private TClient CreateClient <TClient>(IChannel channel) where TClient : ClientBase <TClient>
 {
     if (channel is CoreChannel coreChannel)
     {
         return((TClient)Activator.CreateInstance(typeof(TClient), coreChannel.Channel));
     }
     else if (channel is HttpClientChannel httpClientChannel)
     {
         return(GrpcClientFactory.Create <TClient>(httpClientChannel.BaseAddress, httpClientChannel.HttpClientHandler, loggerFactory));
     }
     else
     {
         throw new Exception("Unexpected channel type.");
     }
 }
예제 #11
0
        public CitiesClient(GrpcClientFactory grpcClientFactory)
        {
            var defaultMethodConfig = new MethodConfig
            {
                Names       = { MethodName.Default },
                RetryPolicy = new RetryPolicy
                {
                    MaxAttempts          = 5,
                    InitialBackoff       = TimeSpan.FromSeconds(1),
                    MaxBackoff           = TimeSpan.FromSeconds(5),
                    BackoffMultiplier    = 1.5,
                    RetryableStatusCodes = { StatusCode.Unavailable }
                }
            };

            _client = grpcClientFactory.CreateClient <Cities.CitiesClient>(nameof(Cities));
        }
예제 #12
0
        public async Task ConnectClientAsync()
        {
            PullNodes.Clear();

            try
            {
                _client = new GrpcClient(ConnectionString, NodeName, GrpcClientFactory.GetDeviceId());

                var pullNodesToAdd = await _client.RegisterNodeAsync(false);

                PullNodes.AddRange(pullNodesToAdd);
            }
            catch (Exception ex)
            {
                // TODO: Log Error.
            }
        }
예제 #13
0
        public static IServiceCollection AddGrpcClient <T>(this IServiceCollection services) where T : class =>
        services.AddTransient(sp =>
        {
            var interceptor = sp.GetService <GrpcClientInterceptor>();
            var httpHandler = sp.GetService <HttpClientHandler>();
            var httpClient  = sp.GetService <HttpClient>();

            var handler = new Grpc.Net.Client.Web.GrpcWebHandler(
                Grpc.Net.Client.Web.GrpcWebMode.GrpcWeb,
                httpHandler ?? new HttpClientHandler());

            var channel = Grpc.Net.Client.GrpcChannel.ForAddress(
                httpClient.BaseAddress,
                new Grpc.Net.Client.GrpcChannelOptions()
            {
                HttpHandler = handler
            });

            var invoker = channel.Intercept(interceptor);

            return(GrpcClientFactory.CreateGrpcService <T>(invoker));
        });
 public Task ConnectAsync()
 {
     _client = GrpcClientFactory.Create <Greeter.GreeterClient>(BaseUri);
     return(Task.CompletedTask);
 }
예제 #15
0
        //public DemoService(Greeter.GreeterClient client)
        //{
        //    //_client = client;
        //}

        public DemoService(GrpcClientFactory grpcClientFactory)
        {
            _client = grpcClientFactory.CreateClient <Greeter.GreeterClient>("Greeter");
        }
예제 #16
0
 public ContactResolver(GrpcClientFactory clientFactory, ILoggerFactory loggerFactory)
 {
     _contactClient = clientFactory.CreateClient <ContactApiClient>(nameof(ContactApiClient));
     _logger        = loggerFactory.CreateLogger <ContactResolver>();
 }
예제 #17
0
 public ContactService(GrpcClientFactory clientFactory, ILoggerFactory loggerFactory) : base()
 {
     _contactClient = clientFactory.CreateClient <ContactApiClient>(nameof(ContactApiClient));
     _logger        = loggerFactory.CreateLogger <ContactService>();
 }
 public ServerProcessInfoController(GrpcClientFactory grpcClientFactory)
 {
     _grpcClientFactory = grpcClientFactory ?? throw new ArgumentNullException(nameof(grpcClientFactory));
 }
예제 #19
0
 public LeadService(GrpcClientFactory clientFactory, ILoggerFactory loggerFactory)
     : base()
 {
     _leadClient = clientFactory.CreateClient<LeadApi.Lead.LeadClient>(nameof(Lead.LeadClient));
     _logger = loggerFactory.CreateLogger<LeadService>();
 }
 public Task ConnectAsync()
 {
     _client = GrpcClientFactory.Create <Greeter.GreeterClient>("https://" + Target);
     return(Task.CompletedTask);
 }