Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions samples/errorhandling/Core_10/ErrorHandling.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shared", "Shared\Shared.csproj", "{A1B2C3D4-E5F6-789A-BCDE-F0123456789A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WithDelayedRetries", "WithDelayedRetries\WithDelayedRetries.csproj", "{B2C3D4E5-F6A7-89BC-DEF0-123456789ABC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WithoutDelayedRetries", "WithoutDelayedRetries\WithoutDelayedRetries.csproj", "{C3D4E5F6-A789-BCDE-F012-3456789ABCDE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlatformLauncher", "PlatformLauncher\PlatformLauncher.csproj", "{D4E5F6A7-89BC-DEF0-1234-56789ABCDEF0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A1B2C3D4-E5F6-789A-BCDE-F0123456789A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A1B2C3D4-E5F6-789A-BCDE-F0123456789A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A1B2C3D4-E5F6-789A-BCDE-F0123456789A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A1B2C3D4-E5F6-789A-BCDE-F0123456789A}.Release|Any CPU.Build.0 = Release|Any CPU
{B2C3D4E5-F6A7-89BC-DEF0-123456789ABC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B2C3D4E5-F6A7-89BC-DEF0-123456789ABC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B2C3D4E5-F6A7-89BC-DEF0-123456789ABC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B2C3D4E5-F6A7-89BC-DEF0-123456789ABC}.Release|Any CPU.Build.0 = Release|Any CPU
{C3D4E5F6-A789-BCDE-F012-3456789ABCDE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C3D4E5F6-A789-BCDE-F012-3456789ABCDE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C3D4E5F6-A789-BCDE-F012-3456789ABCDE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C3D4E5F6-A789-BCDE-F012-3456789ABCDE}.Release|Any CPU.Build.0 = Release|Any CPU
{D4E5F6A7-89BC-DEF0-1234-56789ABCDEF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D4E5F6A7-89BC-DEF0-1234-56789ABCDEF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D4E5F6A7-89BC-DEF0-1234-56789ABCDEF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D4E5F6A7-89BC-DEF0-1234-56789ABCDEF0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<OutputType>Exe</OutputType>
<LangVersion>preview</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Particular.PlatformSample" Version="2.*" />
</ItemGroup>

</Project>
4 changes: 4 additions & 0 deletions samples/errorhandling/Core_10/PlatformLauncher/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
using System;

Console.Title = "PlatformLauncher";
Particular.PlatformLauncher.Launch();
7 changes: 7 additions & 0 deletions samples/errorhandling/Core_10/Shared/MyMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using System;
using NServiceBus;

public record MyMessage : ICommand
{
public required Guid Id { get; init; }
}
12 changes: 12 additions & 0 deletions samples/errorhandling/Core_10/Shared/Shared.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<LangVersion>preview</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NServiceBus" Version="10.0.0-alpha.1" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Concurrent;
using System.Threading.Tasks;
using NServiceBus;

public class MyMessageHandler : IHandleMessages<MyMessage>
{
static readonly ConcurrentDictionary<Guid, string> last = new();

public Task Handle(MyMessage message, IMessageHandlerContext context)
{
Console.WriteLine($"Handling {nameof(MyMessage)} with MessageId:{context.MessageId}");

if (context.MessageHeaders.TryGetValue(Headers.DelayedRetries, out var numOfRetries))
{
last.TryGetValue(message.Id, out var value);

if (numOfRetries != value)
{
Console.WriteLine($"This is retry number {numOfRetries}");
last.AddOrUpdate(message.Id, numOfRetries, (key, oldValue) => numOfRetries);
}
}

throw new Exception("An exception occurred in the handler.");
}
}
33 changes: 33 additions & 0 deletions samples/errorhandling/Core_10/WithDelayedRetries/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Threading.Tasks;
using NServiceBus;

Console.Title = "WithDelayedRetries";

var endpointConfiguration = new EndpointConfiguration("Samples.ErrorHandling.WithDelayedRetries");
endpointConfiguration.UsePersistence<LearningPersistence>();
endpointConfiguration.UseSerialization<SystemJsonSerializer>();
endpointConfiguration.UseTransport(new LearningTransport());

var endpointInstance = await Endpoint.Start(endpointConfiguration);

Console.WriteLine("Press enter to send a message that will throw an exception.");
Console.WriteLine("Press any key to exit");

while (true)
{
var key = Console.ReadKey();
if (key.Key != ConsoleKey.Enter)
{
break;
}

var myMessage = new MyMessage
{
Id = Guid.NewGuid()
};

await endpointInstance.SendLocal(myMessage);
}

await endpointInstance.Stop();
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<OutputType>Exe</OutputType>
<LangVersion>preview</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NServiceBus" Version="10.0.0-alpha.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Shared\Shared.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Threading.Tasks;
using NServiceBus;

#region Handler
public class MyMessageHandler : IHandleMessages<MyMessage>
{
public Task Handle(MyMessage message, IMessageHandlerContext context)
{
Console.WriteLine($"Handling {nameof(MyMessage)} with MessageId:{context.MessageId}");
throw new Exception("An exception occurred in the handler.");
}
}
#endregion
42 changes: 42 additions & 0 deletions samples/errorhandling/Core_10/WithoutDelayedRetries/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Threading.Tasks;
using NServiceBus;

Console.Title = "WithoutDelayedRetries";

#region Disable
var endpointConfiguration = new EndpointConfiguration("Samples.ErrorHandling.WithoutDelayedRetries");
var recoverability = endpointConfiguration.Recoverability();
recoverability.Delayed(
customizations: delayed =>
{
delayed.NumberOfRetries(0);
});
#endregion

endpointConfiguration.UsePersistence<LearningPersistence>();
endpointConfiguration.UseSerialization<SystemJsonSerializer>();
endpointConfiguration.UseTransport(new LearningTransport());

var endpointInstance = await Endpoint.Start(endpointConfiguration);

Console.WriteLine("Press enter to send a message that will throw an exception.");
Console.WriteLine("Press any key to exit");

while (true)
{
var key = Console.ReadKey();
if (key.Key != ConsoleKey.Enter)
{
break;
}

var myMessage = new MyMessage
{
Id = Guid.NewGuid()
};

await endpointInstance.SendLocal(myMessage);
}

await endpointInstance.Stop();
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<OutputType>Exe</OutputType>
<LangVersion>preview</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NServiceBus" Version="10.0.0-alpha.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Shared\Shared.csproj" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions samples/errorhandling/Core_10/prerelease.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
prerelease