-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adding ClusterSingleton
hosting methods
#51
adding ClusterSingleton
hosting methods
#51
Conversation
…ntheweb/Akka.Hosting into cluster/singleton-methods
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.
Reviewed my PR
} | ||
} | ||
|
||
private async Task<IHost> CreateHost(Action<AkkaConfigurationBuilder> specBuilder, ClusterOptions options) |
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.
Created a custom method for spinning up clustered tests hosts - probably need to move this to its own utility class at some point.
var cluster = Cluster.Get(system); | ||
cluster.RegisterOnMemberUp(() => | ||
{ | ||
tcs.SetResult(); |
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.
Set the TaskCompletionSource
once we know we've successfully joined the cluster, at which point the CreateHost
method will exit.
{ | ||
tcs.SetResult(); | ||
}); | ||
if (options.SeedNodes == null || options.SeedNodes.Length == 0) |
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.
If no seed nodes are provided to ClusterOptions
, assume we're the seed node and self-join.
if (options.SeedNodes == null || options.SeedNodes.Length == 0) | ||
{ | ||
var myAddress = cluster.SelfAddress; | ||
await cluster.JoinAsync(myAddress); // force system to wait until we're up |
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.
Otherwise, join the seed nodes provided in configuration.
@@ -162,6 +172,9 @@ public static class AkkaClusterHostingExtensions | |||
.WithRole(shardOptions.Role) | |||
.WithRememberEntities(shardOptions.RememberEntities) | |||
.WithStateStoreMode(shardOptions.StateStoreMode), extractEntityId, extractShardId); | |||
|
|||
// TODO: should throw here if duplicate key used |
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.
Will probably do this in a subsequent PR
/// <param name="actorProps">The underlying actor type. SHOULD NOT BE CREATED USING <see cref="ClusterSingletonManager.Props"/></param> | ||
/// <param name="options">Optional. The set of options for configuring both the <see cref="ClusterSingletonManager"/> and | ||
/// optionally, the <see cref="ClusterSingletonProxy"/>.</param> | ||
/// <param name="createProxyToo">When set to <c>true></c>, creates a <see cref="ClusterSingletonProxy"/> that automatically points to the <see cref="ClusterSingletonManager"/> created by this method.</param> |
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.
It's common for users to create both a ClusterSingletonManager
and a ClusterSingletonProxy
at the same time, so I've made that the default behavior. This method won't store the ClusterSingletonManager
in the ActorRegistry
because there's not much use in doing that - you can't interact with the ClusterSingletonManager
directly - you need the ClusterSingletonProxy
for that. Hence why I've designed the method this way.
singletonProxySettings = singletonProxySettings.WithRole(options.Role); | ||
} | ||
|
||
var singletonProps = options.TerminationMessage == null |
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.
Have to change the way we construct the ClusterSingletonManager
depending upon whether there's a custom termination message or not.
singletonProxySettings = singletonProxySettings.WithBufferSize(options.BufferSize.Value); | ||
} | ||
|
||
CreateAndRegisterSingletonProxy<TKey>($"/user/{singletonManagerRef.Path.Name}", singletonManagerRef.Path.Name, singletonProxySettings, system, registry); |
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.
Created a shared method for instantiating the proxies so we can use the same code in both methods.
/// <param name="singletonName">The name of this singleton instance. Will also be used in the <see cref="ActorPath"/> for the <see cref="ClusterSingletonManager"/> and | ||
/// optionally, the <see cref="ClusterSingletonProxy"/> created by this method.</param> | ||
/// <param name="options">Optional. The set of options for configuring the <see cref="ClusterSingletonProxy"/>.</param> | ||
/// <param name="singletonManagerPath">Optional. By default Akka.Hosting will assume the <see cref="ClusterSingletonManager"/> is hosted at "/user/{singletonName}" - but |
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.
XML-DOC comment explains it all, but this is mostly for backwards compatibility with applications that created singletones without Akka.Hosting and thus the ClusterSingletonManager
names were less standardized.
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.
LGTM, with one comment
* Fixed tags (#14) * Ported over changes in the Petabridge.Library template (#15) * Upgrade to Akka.NET v1.4.35 (#16) Akka.Hosting was affected by akkadotnet/akka.net#5728 * Update RELEASE_NOTES.md (#17) * Bump Akka.Persistence.SqlServer from 1.4.32 to 1.4.35 (#18) Bumps [Akka.Persistence.SqlServer](https://github.com/akkadotnet/Akka.Persistence.SqlServer) from 1.4.32 to 1.4.35. - [Release notes](https://github.com/akkadotnet/Akka.Persistence.SqlServer/releases) - [Changelog](https://github.com/akkadotnet/Akka.Persistence.SqlServer/blob/dev/RELEASE_NOTES.md) - [Commits](akkadotnet/Akka.Persistence.SqlServer@1.4.32...1.4.35) --- updated-dependencies: - dependency-name: Akka.Persistence.SqlServer dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * removed `ClusterShardingSettings` from sharding extensions (#20) * Bump docfx.console from 2.59.0 to 2.59.1 (#19) Bumps [docfx.console](https://github.com/dotnet/docfx) from 2.59.0 to 2.59.1. - [Release notes](https://github.com/dotnet/docfx/releases) - [Changelog](https://github.com/dotnet/docfx/blob/dev/RELEASENOTE.md) - [Commits](dotnet/docfx@v2.59.0...v2.59.1) --- updated-dependencies: - dependency-name: docfx.console dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * added `ShardRegionProxy` support to cluster hosting * added `DistributedPubSub` support * added v0.1.3 release notes * Added `WithCustomSerializer` builder method (#22) * added support for registering custom serializers to `ActorSystem` * added v0.1.4 Release Notes * Bump FluentAssertions from 6.5.1 to 6.6.0 (#24) Bumps [FluentAssertions](https://github.com/fluentassertions/fluentassertions) from 6.5.1 to 6.6.0. - [Release notes](https://github.com/fluentassertions/fluentassertions/releases) - [Changelog](https://github.com/fluentassertions/fluentassertions/blob/develop/AcceptApiChanges.ps1) - [Commits](fluentassertions/fluentassertions@6.5.1...6.6.0) --- updated-dependencies: - dependency-name: FluentAssertions dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump AkkaVersion from 1.4.35 to 1.4.36 (#27) Bumps `AkkaVersion` from 1.4.35 to 1.4.36. Updates `Akka.DependencyInjection` from 1.4.35 to 1.4.36 - [Release notes](https://github.com/akkadotnet/akka.net/releases) - [Changelog](https://github.com/akkadotnet/akka.net/blob/dev/RELEASE_NOTES.md) - [Commits](akkadotnet/akka.net@1.4.35...1.4.36) Updates `Akka.Remote` from 1.4.35 to 1.4.36 - [Release notes](https://github.com/akkadotnet/akka.net/releases) - [Changelog](https://github.com/akkadotnet/akka.net/blob/dev/RELEASE_NOTES.md) - [Commits](akkadotnet/akka.net@1.4.35...1.4.36) Updates `Akka.Cluster.Sharding` from 1.4.35 to 1.4.36 - [Release notes](https://github.com/akkadotnet/akka.net/releases) - [Changelog](https://github.com/akkadotnet/akka.net/blob/dev/RELEASE_NOTES.md) - [Commits](akkadotnet/akka.net@1.4.35...1.4.36) Updates `Akka.Persistence.Query.Sql` from 1.4.35 to 1.4.36 - [Release notes](https://github.com/akkadotnet/akka.net/releases) - [Changelog](https://github.com/akkadotnet/akka.net/blob/dev/RELEASE_NOTES.md) - [Commits](akkadotnet/akka.net@1.4.35...1.4.36) --- updated-dependencies: - dependency-name: Akka.DependencyInjection dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: Akka.Remote dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: Akka.Cluster.Sharding dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: Akka.Persistence.Query.Sql dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * cleanup WithSqlServerPersistence style (#26) * add Akka.Persistence.PostgreSql.Hosting support (#28) * Added v0.1.5 Release Notes (#29) ## [0.1.5] / 06 April 2022 - Added `Akka.Persistence.PostgreSql.Hosting` NuGet package to support Postgres users. * added DI sanity check specs (#31) * Fixed issues with duplicate `IServiceProvider` registration (#32) * commits * fixed DI registration * fixed all remaining DI and instantiation issues * clean up * added Akka.Hosting v0.2.0 release notes (#34) * added v0.2.1 release notes (#35) * Resolve Akka.Remote host binding issue (#37) * adding Akka.Remote.Hosting specs * resolved issue * Added 0.2.2 release notes (#38) ## [0.2.2] / 10 April 2022 - [Bugfix: Akka.Remote.Hosting doesn't support `public-hostname` correctly](#36) * Bump docfx.console from 2.59.1 to 2.59.2 (#39) Bumps [docfx.console](https://github.com/dotnet/docfx) from 2.59.1 to 2.59.2. - [Release notes](https://github.com/dotnet/docfx/releases) - [Changelog](https://github.com/dotnet/docfx/blob/dev/RELEASENOTE.md) - [Commits](dotnet/docfx@v2.59.1...v2.59.2) --- updated-dependencies: - dependency-name: docfx.console dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Added link to explainer video * Update README.md * Bump AkkaVersion from 1.4.36 to 1.4.37 (#41) Bumps `AkkaVersion` from 1.4.36 to 1.4.37. Updates `Akka.DependencyInjection` from 1.4.36 to 1.4.37 - [Release notes](https://github.com/akkadotnet/akka.net/releases) - [Changelog](https://github.com/akkadotnet/akka.net/blob/dev/RELEASE_NOTES.md) - [Commits](akkadotnet/akka.net@1.4.36...1.4.37) Updates `Akka.Remote` from 1.4.36 to 1.4.37 - [Release notes](https://github.com/akkadotnet/akka.net/releases) - [Changelog](https://github.com/akkadotnet/akka.net/blob/dev/RELEASE_NOTES.md) - [Commits](akkadotnet/akka.net@1.4.36...1.4.37) Updates `Akka.Cluster.Sharding` from 1.4.36 to 1.4.37 - [Release notes](https://github.com/akkadotnet/akka.net/releases) - [Changelog](https://github.com/akkadotnet/akka.net/blob/dev/RELEASE_NOTES.md) - [Commits](akkadotnet/akka.net@1.4.36...1.4.37) Updates `Akka.Persistence.Query.Sql` from 1.4.36 to 1.4.37 - [Release notes](https://github.com/akkadotnet/akka.net/releases) - [Changelog](https://github.com/akkadotnet/akka.net/blob/dev/RELEASE_NOTES.md) - [Commits](akkadotnet/akka.net@1.4.36...1.4.37) --- updated-dependencies: - dependency-name: Akka.DependencyInjection dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: Akka.Remote dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: Akka.Cluster.Sharding dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: Akka.Persistence.Query.Sql dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Add interfaces for the ActorRegistry to allow mocking in tests (#42) * Add interfaces to allow the ActorRegistry to be used in unit tests. * Add interfaces to allow the ActorRegistry to be used in unit tests. * Make sure everything compiles again after upstream changes. * Ensure the IActorRegistry and IReadOnlyActorRegistry are registered with DI. Co-authored-by: Aaron Stannard <aaron@petabridge.com> * Bump FluentAssertions from 6.6.0 to 6.7.0 (#47) Bumps [FluentAssertions](https://github.com/fluentassertions/fluentassertions) from 6.6.0 to 6.7.0. - [Release notes](https://github.com/fluentassertions/fluentassertions/releases) - [Changelog](https://github.com/fluentassertions/fluentassertions/blob/develop/AcceptApiChanges.ps1) - [Commits](fluentassertions/fluentassertions@6.6.0...6.7.0) --- updated-dependencies: - dependency-name: FluentAssertions dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump AkkaVersion from 1.4.37 to 1.4.38 (#45) Bumps `AkkaVersion` from 1.4.37 to 1.4.38. Updates `Akka.DependencyInjection` from 1.4.37 to 1.4.38 - [Release notes](https://github.com/akkadotnet/akka.net/releases) - [Changelog](https://github.com/akkadotnet/akka.net/blob/1.4.38/RELEASE_NOTES.md) - [Commits](akkadotnet/akka.net@1.4.37...1.4.38) Updates `Akka.Remote` from 1.4.37 to 1.4.38 - [Release notes](https://github.com/akkadotnet/akka.net/releases) - [Changelog](https://github.com/akkadotnet/akka.net/blob/1.4.38/RELEASE_NOTES.md) - [Commits](akkadotnet/akka.net@1.4.37...1.4.38) Updates `Akka.Cluster.Sharding` from 1.4.37 to 1.4.38 - [Release notes](https://github.com/akkadotnet/akka.net/releases) - [Changelog](https://github.com/akkadotnet/akka.net/blob/1.4.38/RELEASE_NOTES.md) - [Commits](akkadotnet/akka.net@1.4.37...1.4.38) Updates `Akka.Persistence.Query.Sql` from 1.4.37 to 1.4.38 - [Release notes](https://github.com/akkadotnet/akka.net/releases) - [Changelog](https://github.com/akkadotnet/akka.net/blob/1.4.38/RELEASE_NOTES.md) - [Commits](akkadotnet/akka.net@1.4.37...1.4.38) --- updated-dependencies: - dependency-name: Akka.DependencyInjection dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: Akka.Remote dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: Akka.Cluster.Sharding dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: Akka.Persistence.Query.Sql dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump Microsoft.NET.Test.Sdk from 17.1.0 to 17.2.0 (#46) Bumps [Microsoft.NET.Test.Sdk](https://github.com/microsoft/vstest) from 17.1.0 to 17.2.0. - [Release notes](https://github.com/microsoft/vstest/releases) - [Commits](microsoft/vstest@v17.1.0...v17.2.0) --- updated-dependencies: - dependency-name: Microsoft.NET.Test.Sdk dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * close #48 - fixed source of NRE upon shutdown (#49) * close #48 - fixed source of NRE upon shutdown * added NRE check in `StopAsync` * added throw-able `ActorRegistry.Register` method (#50) * added throw-able `ActorRegistry.Register` method * Addressed comments * added null `IActorRef` checks * adding `ClusterSingleton` hosting methods (#51) * adding `ClusterSingleton` hosting methods * fixed compilation errors * added test output logger * fixed package metadata issue * fixed bug with singleton proxy startup * made tests more configurable * working on fixing specs * fixed ClusterSingletonProxy configuration * fixed bug with singleton and proxy method * Update AkkaClusterHostingExtensions.cs * fixed NuGet icon and packaging metadata (#52) * added 0.3.0 release notes (#53) Co-authored-by: Ebere Abanonu <eaba@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: David Cumps <david@cumps.be> Co-authored-by: Sean Farrow <SeanFarrow@users.noreply.github.com>
Adding
ClusterSingletonManager
andClusterSingletonProxy
methods to Akka.Hosting.Changes
Using some of the methods I originally developed here and turning them into something re-usable across end-user projects:
https://github.com/petabridge/akkadotnet-code-samples/blob/108a694421a017aadcbcc5388a98a38fe43a8f74/src/clustering/sharding-sqlserver/SqlSharding.Shared/Sharding/ProductActorProps.cs#L24-L43
Checklist
For significant changes, please ensure that the following have been completed (delete if not relevant):