// TODO: move this method to service private async Task RaiseAdvertConfirmedMessageAsync(ConfirmAdvertDto confirmModel) { var topicArn = _configuration.GetValue <string>("TopicArn"); // To get the title we fetch the advert from db, // or in another way you can pass Title with ConfirmAdvertDto var advert = await _advertStorageService.GetByIdAsync(confirmModel.Id); if (advert == null) { throw new KeyNotFoundException($"Record with Id: {confirmModel.Id} was not found."); } using (var snsClient = new AmazonSimpleNotificationServiceClient()) { var message = new AdvertConfirmedMessage { Id = confirmModel.Id, Title = advert.Title }; var messageJson = JsonConvert.SerializeObject(message); await snsClient.PublishAsync(topicArn, messageJson); } }
private async Task RaiseAdvertConfirmedMessage(ConfirmAdvertModel model) { var topicArn = Configuration.GetValue <string>("TopicArn"); var dbModel = await _advertStorageService.GetById(model.Id); try { using (var client = new AmazonSimpleNotificationServiceClient()) { var message = new AdvertConfirmedMessage { Id = model.Id, Title = dbModel.Title }; var messageJson = JsonConvert.SerializeObject(message); await client.PublishAsync(topicArn, messageJson); } } catch (Exception ex) { Console.WriteLine(ex.Message); throw; } }
public static AdvertType Map(AdvertConfirmedMessage message) { return(new AdvertType { Id = message.Id, Title = message.Title, CreationDateTime = DateTime.UtcNow }); }
public static AdvertType Map(AdvertConfirmedMessage message) { var doc = new AdvertType { Id = message.Id, Title = message.Title, CreationDateTime = DateTime.Now }; return(doc); }
private async Task RaiseAdvertConfirmedMessage(ConfirmAdvertModel model) { var topicArn = _configuration.GetValue <string>("TopicArn"); var dbModel = await _advertStorageService.GetById(model.Id); var message = new AdvertConfirmedMessage { Id = model.Id, Title = dbModel.Title }; var messageJson = JsonConvert.SerializeObject(message); await _notificationService.PublishAsync(topicArn, messageJson); }
private async Task RaiseAdvertConfirmedMessage(ConfirmAdvertModel model) { var topicArn = _configuration.GetValue <string>("TopicArn"); var dbModel = await _advertStorageService.GetByIdAsync(model.Id); using (var client = new AmazonSimpleNotificationServiceClient()) { var message = new AdvertConfirmedMessage { Id = model.Id, Title = dbModel.Title }; var messageJson = JsonSerializer.Serialize(message); await client.PublishAsync(topicArn, messageJson); } }
private async Task RaiseAdvertConfirmedMessage(ConfirmModel model) { var arn = _configuration.GetValue <string>("TopicARN"); using (var client = new AmazonSimpleNotificationServiceClient()) { var message = new AdvertConfirmedMessage() { Id = model.Id, Title = "Advert Model Confirmed" }; _ = await client.PublishAsync(arn, System.Text.Json.JsonSerializer.Serialize(message)); } }
private async Task RaiseAdvertConfirmedMessage(ConfirmAdvertModel model) { string topicUrn = _configuration.GetValue <string>("TopicArn"); var dbModel = await _advertStorageService.GetById(model.Id).ConfigureAwait(false); using var client = new AmazonSimpleNotificationServiceClient(); var message = new AdvertConfirmedMessage { Id = model.Id, Title = dbModel.Title }; string messageJson = JsonConvert.SerializeObject(message); await client.PublishAsync(topicUrn, messageJson).ConfigureAwait(false); }
private async Task RaiseAdvertConfirmedModel(ConfirmAdvertModel model) { var dbModel = await _storageService.GetById(model.Id); var topic = _configuration.GetValue <string>("TopicARN"); AdvertConfirmedMessage advertConfirmedMessage = new AdvertConfirmedMessage() { Id = model.Id, Title = dbModel.Title }; var jsonString = JsonConvert.SerializeObject(advertConfirmedMessage); using (var client = new AmazonSimpleNotificationServiceClient()) { await client.PublishAsync(topic, jsonString); } }
public async Task Function(SNSEvent snsEvent, ILambdaContext context) { foreach (var record in snsEvent.Records) { context.Logger.LogLine(record.Sns.Message); AdvertConfirmedMessage message = JsonConvert.DeserializeObject <AdvertConfirmedMessage>(record.Sns.Message); AdvertType advertDocument = MappingHelper.Map(message); IndexResponse response = await _client.IndexDocumentAsync(advertDocument); context.Logger.LogLine("Result is " + response.Result.ToString()); context.Logger.LogLine("Exception: " + response.OriginalException?.Message); context.Logger.LogLine("Server error: " + response.ServerError); } }
private async Task RaiseAdvertConfirmedMessage(ConfirmAdvertModel model) { var topicArn = "arn:aws:sns:ap-southeast-2:247278111659:AdvertyApi"; var dbModel = await _advertStorageService.GetByIdAsync(model.Id); using (var client = new AmazonSimpleNotificationServiceClient()) { var message = new AdvertConfirmedMessage { Id = model.Id, Title = dbModel.Title }; var messageJson = JsonConvert.SerializeObject(message); await client.PublishAsync(topicArn, messageJson); } }
private async Task RaiseAdvertConfirmMessage(ConfirmAdvertModel model) { var topicArn = _configuration.GetValue <string>("TopicArn"); var advertDbModel = await _advertStorageService.GetByIdAsync(model.Id).ConfigureAwait(false); //that couldnt be a best practice. //don't forget to define role access having access file test/stage or prod enviroment. using (var client = new AmazonSimpleNotificationServiceClient()) { var message = new AdvertConfirmedMessage { Id = model.Id, Title = advertDbModel.Title }; var messageJson = JsonConvert.SerializeObject(message); await client.PublishAsync(topicArn, messageJson); } }
private async Task RaiseAdvertConfirmedMessage(ConfirmAdvertModel model) { using (AmazonSimpleNotificationServiceClient client = new AmazonSimpleNotificationServiceClient()) { string topicArn = Configuration.GetValue <string>("TopicArn"); string dbModelTitle = await _advertStorageService.GetById(model.Id); AdvertConfirmedMessage message = new AdvertConfirmedMessage { Id = model.Id, Title = dbModelTitle }; await testMessage(message.ToString()); var messageJson = JsonConvert.SerializeObject(message); await client.PublishAsync(topicArn, messageJson); } }
public async Task <IActionResult> Raise(string id, string title) { try { var topicArn = Configuration.GetValue <string>("TopicArn"); using (var client = new AmazonSimpleNotificationServiceClient()) { var message = new AdvertConfirmedMessage { Id = id, Title = title }; var messageJson = JsonConvert.SerializeObject(message); await client.PublishAsync(topicArn, messageJson); } } catch (AuthorizationErrorException ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } catch (EndpointDisabledException ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } catch (InternalErrorException ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } catch (InvalidParameterException ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } catch (InvalidParameterValueException ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } catch (InvalidSecurityException ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } catch (KMSAccessDeniedException ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } catch (KMSDisabledException ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } catch (KMSInvalidStateException ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } catch (KMSNotFoundException ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } catch (KMSOptInRequiredException ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } catch (KMSThrottlingException ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } catch (NotFoundException ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } catch (PlatformApplicationDisabledException ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } return(new OkResult()); }