Skip to content

Commit 408cc15

Browse files
[WIP] CQRS example (#161)
* added initial sln structure and nuget packages * imported all message types from shared project * added `ProductTotalsActor` * upgrade to .NET 8 * keep Nuke on .NET 6 * added .NET 6 install back for github actions * defining EF contexts * added EF context * fleshing out backend * got executable up and running * fixed populator script * finished first pass of projector * fixing live execution of data model * fixed missing create event tags
1 parent 64bcae3 commit 408cc15

File tree

51 files changed

+2482
-17
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2482
-17
lines changed

.github/workflows/pr_validation.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ jobs:
3838
run: chmod +x ./build.cmd
3939
- uses: actions/setup-dotnet@v1
4040
with:
41-
dotnet-version: 5.0.*
41+
dotnet-version: 6.0.*
4242
- uses: actions/setup-dotnet@v1
4343
with:
44-
dotnet-version: 6.0.*
44+
dotnet-version: 8.0.*
4545
- name: Cache .nuke/temp, ~/.nuget/packages
4646
uses: actions/cache@v2
4747
with:
@@ -64,10 +64,10 @@ jobs:
6464
run: chmod +x ./build.cmd
6565
- uses: actions/setup-dotnet@v1
6666
with:
67-
dotnet-version: 5.0.*
67+
dotnet-version: 6.0.*
6868
- uses: actions/setup-dotnet@v1
6969
with:
70-
dotnet-version: 6.0.*
70+
dotnet-version: 8.0.*
7171
- name: Cache .nuke/temp, ~/.nuget/packages
7272
uses: actions/cache@v2
7373
with:
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
FROM mcr.microsoft.com/dotnet/runtime:6.0
1+
FROM mcr.microsoft.com/dotnet/runtime:8.0
22
WORKDIR /app
33

4-
COPY ./bin/Release/net6.0/publish/ /app
4+
COPY ./bin/Release/net8.0/publish/ /app
55

66
CMD ["dotnet", "Akka.SqlInitContainer.dll"]

src/Directory.Build.props

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<Copyright>Copyright © 2015-2022 Petabridge, LLC</Copyright>
44
<Authors>Petabridge</Authors>
5-
<VersionPrefix>0.2.0</VersionPrefix>
5+
<VersionPrefix>0.1.0</VersionPrefix>
66
<PackageReleaseNotes>• Initial rewrite of repository</PackageReleaseNotes>
77
<PackageIconUrl>
88
</PackageIconUrl>
@@ -13,7 +13,7 @@
1313
<NoWarn>$(NoWarn);CS1591</NoWarn>
1414
</PropertyGroup>
1515
<PropertyGroup>
16-
<NetRuntime>net6.0</NetRuntime>
16+
<NetRuntime>net8.0</NetRuntime>
1717
<XunitVersion>2.4.2</XunitVersion>
1818
<TestSdkVersion>17.6.0</TestSdkVersion>
1919
<AkkaVersion>1.5.15</AkkaVersion>
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
FROM mcr.microsoft.com/dotnet/runtime:6.0
1+
FROM mcr.microsoft.com/dotnet/runtime:8.0
22
WORKDIR /app
33

4-
COPY ./bin/Release/net6.0/publish/ /app
4+
COPY ./bin/Release/net8.0/publish/ /app
55

66
CMD ["dotnet", "SqlSharding.Host.dll"]

src/clustering/sharding-sqlserver/SqlSharding.Shared/SqlSharding.Shared.csproj

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
<ItemGroup>
1010
<PackageReference Include="Akka.Cluster.Sharding" Version="$(AkkaVersion)" />
1111
<PackageReference Include="Akka.Cluster.Hosting" Version="$(AkkaHostingVersion)" />
12-
<PackageReference Include="Grpc.AspNetCore" Version="2.61.0" />
12+
<PackageReference Include="Grpc.Tools" Version="2.62.0">
13+
<PrivateAssets>all</PrivateAssets>
14+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
15+
</PackageReference>
1316
<PackageReference Include="Bogus" Version="35.5.0" />
1417
</ItemGroup>
1518

Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
FROM mcr.microsoft.com/dotnet/runtime:6.0
1+
FROM mcr.microsoft.com/dotnet/runtime:8.0
22
WORKDIR /app
33

4-
COPY ./bin/Release/net6.0/publish/ /app
4+
COPY ./bin/Release/net8.0/publish/ /app
55

66
CMD ["dotnet", "SqlSharding.Host.dll"]
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
FROM mcr.microsoft.com/dotnet/aspnet:6.0
1+
FROM mcr.microsoft.com/dotnet/aspnet:8.0
22
WORKDIR /app
33

4-
COPY ./bin/Release/net6.0/publish/ /app
4+
COPY ./bin/Release/net8.0/publish/ /app
55

66
CMD ["dotnet", "SqlSharding.WebApp.dll"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// -----------------------------------------------------------------------
2+
// <copyright file="ExponentialBackoffTimeout.cs" company="Akka.NET Project">
3+
// Copyright (C) 2013-2024 .NET Foundation <https://github.com/akkadotnet/akka.net>
4+
// </copyright>
5+
// -----------------------------------------------------------------------
6+
7+
namespace CqrsSqlServer.Backend.Actors;
8+
9+
/// <summary>
10+
/// Utility class for retries / exponential backoff
11+
/// </summary>
12+
public static class ExponentialBackoffTimeout
13+
{
14+
public static TimeSpan BackoffTimeout(int attemptCount, TimeSpan initialTimeout)
15+
{
16+
// going to keep the values small for now
17+
return initialTimeout + attemptCount * TimeSpan.FromSeconds(1);
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// -----------------------------------------------------------------------
2+
// <copyright file="GenericChildPerEntityParent.cs" company="Akka.NET Project">
3+
// Copyright (C) 2013-2024 .NET Foundation <https://github.com/akkadotnet/akka.net>
4+
// </copyright>
5+
// -----------------------------------------------------------------------
6+
7+
using Akka.Actor;
8+
using Akka.Cluster.Sharding;
9+
10+
namespace CqrsSqlServer.Backend.Actors;
11+
12+
/// <summary>
13+
/// A generic "child per entity" parent actor.
14+
/// </summary>
15+
/// <remarks>
16+
/// Intended for simplifying unit tests where we don't want to use Akka.Cluster.Sharding.
17+
/// </remarks>
18+
public sealed class GenericChildPerEntityParent : ReceiveActor
19+
{
20+
public static Props Props(IMessageExtractor extractor, Func<string, Props> propsFactory)
21+
{
22+
return Akka.Actor.Props.Create(() => new GenericChildPerEntityParent(extractor, propsFactory));
23+
}
24+
25+
/*
26+
* Re-use Akka.Cluster.Sharding's infrastructure here to keep things simple.
27+
*/
28+
private readonly IMessageExtractor _extractor;
29+
private Func<string, Props> _propsFactory;
30+
31+
public GenericChildPerEntityParent(IMessageExtractor extractor, Func<string, Props> propsFactory)
32+
{
33+
_extractor = extractor;
34+
_propsFactory = propsFactory;
35+
36+
ReceiveAny(o =>
37+
{
38+
var result = _extractor.EntityId(o);
39+
if (result is null) return;
40+
Context.Child(result).GetOrElse(() => Context.ActorOf(propsFactory(result), result)).Forward(_extractor.EntityMessage(o));
41+
});
42+
}
43+
}

0 commit comments

Comments
 (0)