Skip to content

Instantly share code, notes, and snippets.

@fardeen9983
Created April 13, 2022 11:56
Show Gist options
  • Save fardeen9983/0ed87423f70708de7531b6a32d3e09a2 to your computer and use it in GitHub Desktop.
Save fardeen9983/0ed87423f70708de7531b6a32d3e09a2 to your computer and use it in GitHub Desktop.
Notification Service Implementation
using Amazon.SimpleNotificationService;
using Amazon.SimpleNotificationService.Model;
using Microsoft.Extensions.Configuration;
using System;
using System.Threading.Tasks;
namespace CodePanthers.AWS.S3.UploadService.Services
{
public class NotificationService : INotificationService
{
private readonly IAmazonSimpleNotificationService _snsService;
private readonly string TopicArn;
public NotificationService(IAmazonSimpleNotificationService snsService, IConfiguration Configuration)
{
_snsService = snsService;
TopicArn = Configuration["SNSTopicArn"];
}
public async Task RegisterSubscirption(string topic, string email)
{
try
{
await _snsService.SubscribeAsync(topic, "email", email);
}
catch (Exception)
{
throw;
}
}
public async Task RegisterSubscirption(string email)
{
try
{
await _snsService.SubscribeAsync(TopicArn, "email", email);
}
catch (Exception)
{
throw;
}
}
public async Task SendUploadNotification( string topic, string message)
{
try
{
var request = new PublishRequest
{
Message = message,
TopicArn = topic,
};
await _snsService.PublishAsync(request);
}
catch (Exception)
{
throw;
}
}
public async Task SendUploadNotification(string message)
{
try
{
var request = new PublishRequest
{
Message = message,
TopicArn = TopicArn,
};
await _snsService.PublishAsync(request);
}
catch (Exception)
{
throw;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment