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(); }
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; }
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)); }
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)); }
public CartsController(CartRepository cartRepository, CartItemRepository cartItemRepository, CartService cartService, GrpcClientFactory grpcClientFactory) { _cartRepository = cartRepository; _cartItemRepository = cartItemRepository; _cartService = cartService; _grpcClientFactory = grpcClientFactory; }
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; }
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."); } }
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."); } }
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)); }
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. } }
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); }
//public DemoService(Greeter.GreeterClient client) //{ // //_client = client; //} public DemoService(GrpcClientFactory grpcClientFactory) { _client = grpcClientFactory.CreateClient <Greeter.GreeterClient>("Greeter"); }
public ContactResolver(GrpcClientFactory clientFactory, ILoggerFactory loggerFactory) { _contactClient = clientFactory.CreateClient <ContactApiClient>(nameof(ContactApiClient)); _logger = loggerFactory.CreateLogger <ContactResolver>(); }
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)); }
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); }