public async Task <IActionResult> ProcessTenantTopic([FromBody] TopicData <Tenant> tenantTopicData) { if (!string.IsNullOrWhiteSpace(tenantTopicData.Data.Id)) { _logger.LogInformation($"Receive tenant topic type {tenantTopicData.TopicType} id: {tenantTopicData.Data.Id}"); string cacheKey = $"{CacheConstant.Tenant_}{tenantTopicData.Data.Id}"; switch (tenantTopicData.TopicType) { case TopicType.Remove: await _tenantCacheService.ClearCacheAsync(_daprClient, cacheKey); break; case TopicType.Modify: await _tenantCacheService.UpdateCacheAsync(_daprClient, cacheKey, tenantTopicData.Data); break; } } else { _logger.LogWarning($"Receive tenant topic without id"); } return(Ok()); }
public static async Task <Tenant> SearchTenantByIdAsync( ILogger logger, IStringLocalizer <TenantFrameworkResource> sl, TenantCacheService tenantCacheService, DaprClient daprClient, string tenantId) { try { string cacheKey = $"{CacheConstant.Tenant_}{tenantId}"; var tenant = await tenantCacheService.GetCacheAsync(daprClient, cacheKey); if (tenant == null) { var secretValues = await daprClient.GetSecretAsync(ConfigConstant.CodexKey, ConfigConstant.MicroserviceApiKey); var microserviceApiKey = secretValues[ConfigConstant.MicroserviceApiKey]; tenant = await daprClient.InvokeMethodAsync <Tenant>(ApiNameConstant.TenantApi, $"Tenant/{tenantId}", new HTTPExtension() { Verb = HTTPVerb.Get, Headers = { { HttpHeaderConstant.TenantId, tenantId }, { HttpHeaderConstant.ApiKey, $"{tenantId}.{microserviceApiKey}" } } } ); await tenantCacheService.UpdateCacheAsync(daprClient, cacheKey, tenant); return(tenant); } else { return(tenant); } } catch (Exception exception) { if (exception is Grpc.Core.RpcException rpcException && rpcException.Status.StatusCode == Grpc.Core.StatusCode.NotFound) { logger.LogInformation(rpcException, $"Tenant not found : '{tenantId}'"); throw new InvalidTenantIdException($"{sl[TenantFrameworkResource.TENANT_NOT_FOUND]!} : '{tenantId}'", "TENANT_NOT_FOUND"); } logger.LogError(exception, $"Unable to find Tenant {tenantId}"); throw new TechnicalException($"{sl[TenantFrameworkResource.TENANT_NOT_FOUND]!} : '{tenantId}'", "TENANT_NOT_FOUND"); } }