예제 #1
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 ProductProtoService.ProductProtoServiceClient(channel);

                    _logger.LogInformation("AddProductAsync started..");
                    var addProductResponse = await client.AddProductAsync(await _factory.Generate());

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

                await Task.Delay(_config.GetValue <int>("WorkerService:TaskInterval"), stoppingToken);
            }
        }
        private static async Task AddProductAsync(ProductProtoService.ProductProtoServiceClient client)
        {
            var addProductResponse = await client.AddProductAsync(new AddProductRequest
            {
                Product = new ProductModel
                {
                    Name        = "Test_2",
                    Description = "This is a test_2 product.",
                    Price       = 100,
                    Status      = ProductStatus.Instock,
                    CreatedTime = Timestamp.FromDateTime(DateTime.UtcNow)
                }
            });;

            Console.WriteLine("Added Product:-" + addProductResponse.ToString());
        }
예제 #3
0
        private static async Task AddProductAsync(ProductProtoService.ProductProtoServiceClient client)
        {
            Console.WriteLine("AddProductAsync started...");
            var response = await client.AddProductAsync(new AddProductRequest
            {
                Product = new ProductModel
                {
                    Name        = "Red",
                    Description = "New Red Phone Mi10T",
                    Price       = 699,
                    Status      = ProductStatus.InStock,
                    CreatedDate = Timestamp.FromDateTime(DateTime.UtcNow)
                }
            });

            Console.WriteLine("AddProductAsync response: " + response.ToString());
        }
예제 #4
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            Console.WriteLine("Waitting for Server is running.....");
            Thread.Sleep(2000);
            while (!stoppingToken.IsCancellationRequested)
            {
                _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
                using var channel = GrpcChannel.ForAddress(_config.GetValue <string>("WorkerService:ServerUrl"));
                var client = new ProductProtoService.ProductProtoServiceClient(channel);
                _logger.LogInformation("AddProductAsyn started....");
                var addProductAsync = await client.AddProductAsync(await _factory.Gennerate());

                _logger.LogInformation("AddProductAsyn Response:" + addProductAsync.ToString());

                await Task.Delay(_config.GetValue <int>("WorkerService:TakeInterval"), stoppingToken);
            }
        }
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);

                using var channel = GrpcChannel.ForAddress(_configuration.GetValue <string>("WorkerService:ServerUrl"));

                var client = new ProductProtoService.ProductProtoServiceClient(channel);

                //  await GetProdudtAsync(client);
                // await AddProductAsync(client);
                var addProductFactory = await client.AddProductAsync(await _productFactory.Generate());

                _logger.LogInformation("Add Product Response :{Product}", addProductFactory.ToString());
                await Task.Delay(_configuration.GetValue <int>("WorkerService:TaskInterval"), stoppingToken);
            }
        }