-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove Message base class #685
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
using System.Threading.Tasks; | ||
using JustSaying.Messaging.MessageHandling; | ||
using JustSaying.Messaging.Monitoring; | ||
using JustSaying.Models; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace JustSaying.AwsTools.MessageHandling | ||
|
@@ -23,19 +22,19 @@ public MessageHandlerWrapper( | |
_loggerFactory = loggerFactory; | ||
} | ||
|
||
public Func<Message, Task<bool>> WrapMessageHandler<T>(Func<IHandlerAsync<T>> futureHandler) where T : Message | ||
public Func<object, Task<bool>> WrapMessageHandler<T>(Func<IHandlerAsync<T>> futureHandler, Func<T, string> uniqueKeySelector = default) where T : class | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it not possible to just use the SNS/SQS message ID for the unique key? Why does it have to be a value in the domain message? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original thinking behind this was that only the developer knows what determines the messages identity, and what is a duplicate. Perhaps the event publisher has OrderId and that is the real identity of the message, or a composite of OrderId and Status. Maybe it's a hash of all of the properties on the message? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. And with the benefit of hindsight, has that thinking paid off? Perhaps it's better to remove this "exactly once" functionality from this library and force consumers to make their solutions inherently idempotent in the domain rather than only at the message bus layer? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You know: Smart Endpoints and Dumb Pipes |
||
{ | ||
return async message => | ||
{ | ||
var handler = futureHandler(); | ||
handler = MaybeWrapWithExactlyOnce(handler); | ||
handler = MaybeWrapWithExactlyOnce(handler, uniqueKeySelector); | ||
handler = MaybeWrapWithStopwatch(handler); | ||
|
||
return await handler.Handle((T)message).ConfigureAwait(false); | ||
}; | ||
} | ||
|
||
private IHandlerAsync<T> MaybeWrapWithExactlyOnce<T>(IHandlerAsync<T> handler) where T : Message | ||
private IHandlerAsync<T> MaybeWrapWithExactlyOnce<T>(IHandlerAsync<T> handler, Func<T, string> uniqueKeySelector) where T : class | ||
{ | ||
var handlerType = handler.GetType(); | ||
var exactlyOnceMetadata = new ExactlyOnceReader(handlerType); | ||
|
@@ -49,14 +48,19 @@ private IHandlerAsync<T> MaybeWrapWithExactlyOnce<T>(IHandlerAsync<T> handler) w | |
throw new Exception("IMessageLock is null. You need to specify an implementation for IMessageLock."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should change this to |
||
} | ||
|
||
if (uniqueKeySelector == null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should throw this in the caller before we start to do any work, rather than in the delegate further along the call path. |
||
{ | ||
throw new ArgumentNullException(nameof(uniqueKeySelector), "You must specify a uniqueKeySelector in order to use exactly once functionality."); | ||
} | ||
|
||
var handlerName = handlerType.FullName.ToLowerInvariant(); | ||
var timeout = TimeSpan.FromSeconds(exactlyOnceMetadata.GetTimeOut()); | ||
var logger = _loggerFactory.CreateLogger<ExactlyOnceHandler<T>>(); | ||
|
||
return new ExactlyOnceHandler<T>(handler, _messageLock, timeout, handlerName, logger); | ||
return new ExactlyOnceHandler<T>(handler, _messageLock, uniqueKeySelector, timeout, handlerName, logger); | ||
} | ||
|
||
private IHandlerAsync<T> MaybeWrapWithStopwatch<T>(IHandlerAsync<T> handler) where T : Message | ||
private IHandlerAsync<T> MaybeWrapWithStopwatch<T>(IHandlerAsync<T> handler) where T : class | ||
{ | ||
if (!(_messagingMonitor is IMeasureHandlerExecutionTime executionTimeMonitoring)) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,6 @@ | |
using JustSaying.Messaging.MessageSerialization; | ||
using JustSaying.Messaging.Monitoring; | ||
using Microsoft.Extensions.Logging; | ||
using Message = JustSaying.Models.Message; | ||
|
||
namespace JustSaying.AwsTools.MessageHandling | ||
{ | ||
|
@@ -93,7 +92,7 @@ public SqsNotificationListener WithMessageProcessingStrategy(IMessageProcessingS | |
return this; | ||
} | ||
|
||
public void AddMessageHandler<T>(Func<IHandlerAsync<T>> futureHandler) where T : Message | ||
public void AddMessageHandler<T>(Func<IHandlerAsync<T>> futureHandler, Func<T, string> uniqueKeySelector = default) where T : class | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is optional, how does it avoid causing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow. I didn't know there was a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There isn't, well there is, it's just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, haha. I don't know why I assumed otherwise. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
{ | ||
if (_handlerMap.ContainsKey(typeof(T))) | ||
{ | ||
|
@@ -103,7 +102,7 @@ public void AddMessageHandler<T>(Func<IHandlerAsync<T>> futureHandler) where T : | |
|
||
Subscribers.Add(new Subscriber(typeof(T))); | ||
|
||
var handlerFunc = _messageHandlerWrapper.WrapMessageHandler(futureHandler); | ||
var handlerFunc = _messageHandlerWrapper.WrapMessageHandler(futureHandler, uniqueKeySelector); | ||
_handlerMap.Add(typeof(T), handlerFunc); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So here it is, the one place where we actually do something with a property on
Message
(ok, there wasUniqueKey()
too I guess). It's on a trace log, we arguably would want to use the SQS message id for this level of debugging, but tying it back to the domain event is going to be the challenge.