Skip to content

Commit

Permalink
Changed Notification to Message (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kralizek authored and derwasp committed Sep 9, 2018
1 parent 87032ff commit f671098
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
10 changes: 10 additions & 0 deletions src/Kralizek.Lambda.Template.Sqs/IMessageHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Threading.Tasks;
using Amazon.Lambda.Core;

namespace Kralizek.Lambda
{
public interface IMessageHandler<in TMessage> where TMessage : class
{
Task HandleAsync(TMessage message, ILambdaContext context);
}
}
10 changes: 0 additions & 10 deletions src/Kralizek.Lambda.Template.Sqs/INotificationHandler.cs

This file was deleted.

10 changes: 5 additions & 5 deletions src/Kralizek.Lambda.Template.Sqs/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ namespace Kralizek.Lambda
{
public static class ServiceCollectionExtensions
{
public static IServiceCollection UseSqsHandler<TNotification, THandler>(this IServiceCollection services)
where TNotification : class
where THandler : class, INotificationHandler<TNotification>
public static IServiceCollection UseSqsHandler<TMessage, THandler>(this IServiceCollection services)
where TMessage : class
where THandler : class, IMessageHandler<TMessage>
{
services.AddTransient<IEventHandler<SQSEvent>, SqsEventHandler<TNotification>>();
services.AddTransient<IEventHandler<SQSEvent>, SqsEventHandler<TMessage>>();

services.AddTransient<INotificationHandler<TNotification>, THandler>();
services.AddTransient<IMessageHandler<TMessage>, THandler>();

return services;
}
Expand Down
14 changes: 7 additions & 7 deletions src/Kralizek.Lambda.Template.Sqs/SqsEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Kralizek.Lambda
{
public class SqsEventHandler<TNotification> : IEventHandler<SQSEvent> where TNotification : class
public class SqsEventHandler<TMessage> : IEventHandler<SQSEvent> where TMessage : class
{
private readonly ILogger _logger;
private readonly IServiceProvider _serviceProvider;
Expand All @@ -25,19 +25,19 @@ public async Task HandleAsync(SQSEvent input, ILambdaContext context)
{
using (_serviceProvider.CreateScope())
{
var message = record.Body;
var notification = JsonConvert.DeserializeObject<TNotification>(message);
var sqsMessage = record.Body;
var message = JsonConvert.DeserializeObject<TMessage>(sqsMessage);

var handler = _serviceProvider.GetService<INotificationHandler<TNotification>>();
var handler = _serviceProvider.GetService<IMessageHandler<TMessage>>();

if (handler == null)
{
_logger.LogCritical($"No INotificationHandler<{typeof(TNotification).Name}> could be found.");
throw new InvalidOperationException($"No INotificationHandler<{typeof(TNotification).Name}> could be found.");
_logger.LogCritical($"No IMessageHandler<{typeof(TMessage).Name}> could be found.");
throw new InvalidOperationException($"No IMessageHandler<{typeof(TMessage).Name}> could be found.");
}

_logger.LogInformation("Invoking notification handler");
await handler.HandleAsync(notification, context);
await handler.HandleAsync(message, context);
}
}
}
Expand Down

0 comments on commit f671098

Please sign in to comment.