-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved error reporting for reflection based handling rules
- Loading branch information
1 parent
0df2773
commit 7d98fd9
Showing
5 changed files
with
102 additions
and
39 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using Platibus.Diagnostics; | ||
using System; | ||
using System.Reflection; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Platibus.Config | ||
{ | ||
internal class HandlerActivation : IMessageHandler | ||
{ | ||
private readonly IDiagnosticService _diagnosticService; | ||
private readonly Type _handlerType; | ||
private readonly Func<object> _handlerFactory; | ||
private readonly MethodInfo _method; | ||
|
||
public HandlerActivation(IDiagnosticService diagnosticService, Type handlerType, Func<object> handlerFactory, MethodInfo method) | ||
{ | ||
_diagnosticService = diagnosticService; | ||
_handlerType = handlerType; | ||
_handlerFactory = handlerFactory; | ||
_method = method; | ||
} | ||
|
||
public async Task HandleMessage(object content, IMessageContext messageContext, CancellationToken cancellationToken) | ||
{ | ||
try | ||
{ | ||
var handler = _handlerFactory(); | ||
if (handler == null && !_method.IsStatic) | ||
{ | ||
throw new NullReferenceException("Handler factory returned null handler instance"); | ||
} | ||
await (Task)_method.Invoke(handler, new[] { content, messageContext, cancellationToken }); | ||
} | ||
catch (Exception e) | ||
{ | ||
_diagnosticService.Emit(new DiagnosticEventBuilder(null, DiagnosticEventType.HandlerActivationError) | ||
{ | ||
Detail = $"Error activating instance of message handler {_handlerType}: {e.Message}", | ||
Exception = e | ||
}.Build()); | ||
throw; | ||
} | ||
} | ||
} | ||
} |
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
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