-
-
Save BavoLuysterborg/4e6a58546cd498701cafb56ccad0e21e to your computer and use it in GitHub Desktop.
Repro for Rebus TransactionAbortedException issue
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
namespace Repro | |
{ | |
public class ErrorMessage | |
{ | |
public string Message { get; } = "Error"; | |
} | |
} |
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 Microsoft.Extensions.Logging; | |
using Rebus.Handlers; | |
using Rebus.Retry.Simple; | |
namespace Repro | |
{ | |
public class ErrorMessageHandler : IHandleMessages<ErrorMessage>, IHandleMessages<IFailed<ErrorMessage>> | |
{ | |
private readonly ILogger<ErrorMessageHandler> _log; | |
public ErrorMessageHandler(ILogger<ErrorMessageHandler> log) { | |
_log = log; | |
} | |
public async Task Handle(ErrorMessage message) | |
{ | |
_log.LogInformation("Handling ErrorMessage"); | |
throw new Exception(message.Message); | |
} | |
public async Task Handle(IFailed<ErrorMessage> message) | |
{ | |
_log.LogInformation("Handling 2ndLevelRetry for ErrorMessage"); | |
} | |
} | |
} |
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 Microsoft.Extensions.DependencyInjection; | |
using Microsoft.Extensions.Hosting; | |
using Microsoft.Extensions.Logging; | |
using Rebus.Config; | |
using Rebus.Retry.Simple; | |
using Rebus.Routing.TypeBased; | |
using Rebus.Transport.FileSystem; | |
using Repro; | |
using System.Transactions; | |
await Host.CreateDefaultBuilder() | |
.AddRebusService(services => | |
{ | |
services.AddLogging(l => l.AddConsole()); | |
services.AutoRegisterHandlersFromAssemblyOf<ErrorMessageHandler>(); | |
services.AddRebus(configure => configure | |
.Transport(t => t.UseFileSystem( | |
Path.GetFullPath(Path.Combine(new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory).FullName, @".bus")), | |
"test_queue")) | |
.Logging(l => l.Console()) | |
.Options(o => | |
{ | |
o.RetryStrategy(secondLevelRetriesEnabled: true, maxDeliveryAttempts: 2); | |
o.HandleMessagesInsideTransactionScope(new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted, Timeout = default }); | |
}) | |
.Routing(r => r.TypeBased()), | |
onCreated: async bus => await bus.SendLocal(new ErrorMessage())); | |
}) | |
.RunConsoleAsync(); |
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
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>net8.0</TargetFramework> | |
<ImplicitUsings>enable</ImplicitUsings> | |
<Nullable>enable</Nullable> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" /> | |
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" /> | |
<PackageReference Include="Rebus" Version="8.2.2" /> | |
<PackageReference Include="Rebus.ServiceProvider" Version="10.1.0" /> | |
<PackageReference Include="Rebus.TransactionScopes" Version="7.0.0" /> | |
</ItemGroup> | |
</Project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment