Skip to content

Instantly share code, notes, and snippets.

@AnthonySteele
Created November 30, 2018 09:17
Show Gist options
  • Save AnthonySteele/45f72131e5470cfdf31b83831910a96c to your computer and use it in GitHub Desktop.
Save AnthonySteele/45f72131e5470cfdf31b83831910a96c to your computer and use it in GitHub Desktop.
using System.Threading.Tasks;
using SqsMessage = Amazon.SQS.Model.Message;
namespace JustSaying.Messaging.MessageHandling
{
public interface IHandlerAsync<in T>
{
/// <summary>
/// Handle a message of a given type
/// </summary>
/// <param name="message">Message to handle</param>
/// <returns>Was handling successful?</returns>
Task<bool> Handle(T message);
}
/// <summary>
/// Async message handler
/// </summary>
/// <typeparam name="T">Type of message to be handled</typeparam>
public interface IRawHandlerAsync<in T>
{
/// <summary>
/// Handle a message of a given type and also access SQS metadata
/// </summary>
/// <param name="message">Message to handle</param>
/// <param name="rawMessage">Raw SQS data</param>
/// <returns>Was handling successful?</returns>
Task<bool> Handle(T message, SqsMessage rawMessage);
}
public class HandlerShim<T> : IRawHandlerAsync<T>
{
private readonly IHandlerAsync<T> _inner;
public HandlerShim(IHandlerAsync<T> inner)
{
_inner = inner;
}
public Task<bool> Handle(T message, SqsMessage rawMessage)
{
return _inner.Handle(message);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment