-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
76d3ea1
commit acdc486
Showing
22 changed files
with
876 additions
and
31 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,103 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Nybus.Filters | ||
{ | ||
public class DeadLetterQueueErrorFilterProvider : IErrorFilterProvider | ||
{ | ||
private readonly IServiceProvider _serviceProvider; | ||
|
||
public DeadLetterQueueErrorFilterProvider(IServiceProvider serviceProvider) | ||
{ | ||
_serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider)); | ||
} | ||
|
||
public string ProviderName { get; } = "dead-letter-queue"; | ||
|
||
public IErrorFilter CreateErrorFilter(IConfigurationSection settings) | ||
{ | ||
var engine = _serviceProvider.GetRequiredService<IBusEngine>(); | ||
var logger = _serviceProvider.GetRequiredService<ILogger<DeadLetterQueueErrorFilter>>(); | ||
|
||
return new DeadLetterQueueErrorFilter(logger, engine); | ||
} | ||
} | ||
|
||
public class DeadLetterQueueErrorFilter : IErrorFilter | ||
{ | ||
private readonly ILogger<DeadLetterQueueErrorFilter> _logger; | ||
private readonly IBusEngine _engine; | ||
|
||
public DeadLetterQueueErrorFilter(ILogger<DeadLetterQueueErrorFilter> logger, IBusEngine engine) | ||
{ | ||
_logger = logger ?? throw new ArgumentNullException(nameof(logger)); | ||
_engine = engine ?? throw new ArgumentNullException(nameof(engine)); | ||
} | ||
|
||
public async Task HandleErrorAsync<TCommand>(ICommandContext<TCommand> context, Exception exception, CommandErrorDelegate<TCommand> next) where TCommand : class, ICommand | ||
{ | ||
try | ||
{ | ||
_logger.LogTrace($"Sending command to dead letter queue"); | ||
|
||
await SendToErrorQueue(context.Message, exception); | ||
} | ||
catch (Exception dlqException) | ||
{ | ||
_logger.LogError(new { }, dlqException, (s, ex) => $"Unable to send message to DLQ: {ex.Message}"); | ||
await next(context, exception).ConfigureAwait(false); | ||
} | ||
} | ||
|
||
public async Task HandleErrorAsync<TEvent>(IEventContext<TEvent> context, Exception exception, EventErrorDelegate<TEvent> next) where TEvent : class, IEvent | ||
{ | ||
try | ||
{ | ||
_logger.LogTrace($"Sending event to dead letter queue"); | ||
|
||
await SendToErrorQueue(context.Message, exception); | ||
} | ||
catch (Exception dlqException) | ||
{ | ||
_logger.LogError(new { }, dlqException, (s, ex) => $"Unable to send message to DLQ: {ex.Message}"); | ||
await next(context, exception).ConfigureAwait(false); | ||
} | ||
} | ||
|
||
private async Task SendToErrorQueue(Message message, Exception exception) | ||
{ | ||
if (exception != null) | ||
{ | ||
message.Headers[DeadLetterQueueHeaders.FaultMessage] = exception.Message; | ||
message.Headers[DeadLetterQueueHeaders.FaultStackTrace] = exception.StackTrace; | ||
} | ||
|
||
message.Headers[DeadLetterQueueHeaders.ErrorHost] = Environment.MachineName; | ||
message.Headers[DeadLetterQueueHeaders.ErrorProcess] = Process.GetCurrentProcess().ProcessName; | ||
|
||
var entryAssembly = Assembly.GetEntryAssembly(); | ||
if (entryAssembly != null) | ||
{ | ||
message.Headers[DeadLetterQueueHeaders.ErrorAssembly] = entryAssembly.GetName().Name; | ||
} | ||
|
||
await _engine.NotifySuccessAsync(message).ConfigureAwait(false); | ||
|
||
await _engine.SendMessageToErrorQueueAsync(message).ConfigureAwait(false); | ||
} | ||
} | ||
|
||
public static class DeadLetterQueueHeaders | ||
{ | ||
public static readonly string FaultMessage = "DLQ-Fault-Message"; | ||
public static readonly string FaultStackTrace = "DLQ-Fault-StackTrace"; | ||
public static readonly string ErrorHost = "DLQ-Error-Host"; | ||
public static readonly string ErrorProcess = "DLQ-Error-Process"; | ||
public static readonly string ErrorAssembly = "DLQ-Error-Assembly"; | ||
} | ||
} |
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
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
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
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,14 @@ | ||
using System; | ||
|
||
namespace Tests | ||
{ | ||
public class TestException : Exception | ||
{ | ||
public TestException(string message, string stackTrace) : base(message) | ||
{ | ||
StackTrace = stackTrace; | ||
} | ||
|
||
public override string StackTrace { get; } | ||
} | ||
} |
Oops, something went wrong.
acdc486
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.
@elindanielsson could you check the failed build?
acdc486
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.
I'm not sure what happened there, looks like the latest build is green @Kralizek
acdc486
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.
Yup. It's some kind of flaky test.
acdc486
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.
@Kralizek I don't know if you saw, but looks like there was an error creating the release: https://ci.appveyor.com/project/Kralizek/nybus/builds/42275426
acdc486
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.
I'll give a look at it tomorrow
acdc486
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.
Hey @Kralizek , have you had a chance to look at the build error when creating the release?
acdc486
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.
I pushed the 1.6.0 packages manually