Created
November 30, 2018 09:17
-
-
Save AnthonySteele/45f72131e5470cfdf31b83831910a96c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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