Ejemplo n.º 1
0
        private static async Task AddProductAsync(ProductProtoServiceClient client)
        {
            Console.WriteLine("AddProductAsync started...");
            var addProduct = await client.AddProductAsync(new AddProductRequest {
                Product = new ProductModel
                {
                    Name        = "Red",
                    Description = "New Red Phone Mi10T",
                    Price       = 699,
                    Status      = ProductStatus.Instock,
                    CreatedTime = Timestamp.FromDateTime(DateTime.UtcNow)
                }
            });

            Console.WriteLine($"AddProduct Response: {addProduct.ToString()}");
            Thread.Sleep(1000);
        }
Ejemplo n.º 2
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);

                try
                {
                    using var channel = GrpcChannel.ForAddress(_config.GetValue <string>("WorkerService:ServerUrl"));
                    var client = new ProductProtoServiceClient(channel);
                    _logger.LogInformation("AddProductAsync started..");
                    var addProductResponse = await client.AddProductAsync(await _productFactory.Generate());

                    _logger.LogInformation("AddProduct Response: {product}", addProductResponse.ToString());
                }
                catch (Exception exception)
                {
                    _logger.LogError(exception.Message);
                    throw;
                }

                await Task.Delay(_config.GetValue <int>("WorkerService:TaskInterval"), stoppingToken);
            }
        }