diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index eb39246e..48dba0db 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,2 +1,3 @@ -## [0.1.2] / 31 March 2022 -- Removed all `Cluster.Sharding` methods that rely on `ClusterShardingSettings`, since it's not practical to create those prior to starting the `ActorSystem`. +## [0.1.3] / 31 March 2022 +- Added `ShardRegionProxy` support to Akka.Cluster.Hosting +- Added `DistributedPubSub` support to Akka.Cluster.Hosting diff --git a/src/Akka.Cluster.Hosting/AkkaClusterHostingExtensions.cs b/src/Akka.Cluster.Hosting/AkkaClusterHostingExtensions.cs index d0473d7d..c91e93ba 100644 --- a/src/Akka.Cluster.Hosting/AkkaClusterHostingExtensions.cs +++ b/src/Akka.Cluster.Hosting/AkkaClusterHostingExtensions.cs @@ -164,5 +164,85 @@ public static AkkaConfigurationBuilder WithShardRegion(this AkkaConfigurat registry.TryRegister(shardRegion); }); } + + /// + /// Starts a ShardRegionProxy that points to a hosted on a different role inside the cluster + /// and registers the with in the + /// for this . + /// + /// The builder instance being configured. + /// The name of the entity type + /// The role of the Akka.Cluster member that is hosting this . + /// + /// Partial function to extract the entity id and the message to send to the entity from the incoming message, + /// if the partial function does not match the message will be `unhandled`, + /// i.e.posted as `Unhandled` messages on the event stream + /// + /// + /// Function to determine the shard id for an incoming message, only messages that passed the `extractEntityId` will be used + /// + /// The type key to use to retrieve the for this . + /// The same instance originally passed in. + public static AkkaConfigurationBuilder WithShardRegionProxy(this AkkaConfigurationBuilder builder, + string typeName, string roleName, ExtractEntityId extractEntityId, ExtractShardId extractShardId) + { + return builder.WithActors(async (system, registry) => + { + var shardRegionProxy = await ClusterSharding.Get(system) + .StartProxyAsync(typeName, roleName, extractEntityId, extractShardId); + registry.TryRegister(shardRegionProxy); + }); + } + + /// + /// Starts a ShardRegionProxy that points to a hosted on a different role inside the cluster + /// and registers the with in the + /// for this . + /// + /// The builder instance being configured. + /// The name of the entity type + /// The role of the Akka.Cluster member that is hosting this . + /// + /// Functions to extract the entity id, shard id, and the message to send to the entity from the incoming message. + /// + /// The type key to use to retrieve the for this . + /// The same instance originally passed in. + public static AkkaConfigurationBuilder WithShardRegionProxy(this AkkaConfigurationBuilder builder, + string typeName, string roleName, IMessageExtractor messageExtractor) + { + return builder.WithActors(async (system, registry) => + { + var shardRegionProxy = await ClusterSharding.Get(system) + .StartProxyAsync(typeName, roleName, messageExtractor); + registry.TryRegister(shardRegionProxy); + }); + } + + /// + /// Starts on this node immediately upon startup. + /// + /// The builder instance being configured. + /// Specifies which role will broadcast gossip to. If this value + /// is left blank then ALL roles will be targeted. + /// The same instance originally passed in. + /// + /// Stores the mediator in the registry using the key. + /// + public static AkkaConfigurationBuilder WithDistributedPubSub(this AkkaConfigurationBuilder builder, + string role) + { + var middle = builder.AddHocon(DistributedPubSub.DefaultConfig()); + if (!string.IsNullOrEmpty(role)) // add role config + { + middle = middle.AddHocon($"akka.cluster.pub-sub = \"{role}\""); + } + + return middle.WithActors((system, registry) => + { + // force the initialization + var mediator = DistributedPubSub.Get(system).Mediator; + registry.TryRegister(mediator); + }); + } } } \ No newline at end of file diff --git a/src/Directory.Build.props b/src/Directory.Build.props index bb408a45..6cfd5247 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -2,8 +2,9 @@ Copyright © 2013-2022 Akka.NET Team Akka.NET Team - 0.1.2 - • Removed all Cluster.Sharding methods that rely on ClusterShardingSettings%2C since it's not practical to create those prior to starting the ActorSystem. + 0.1.3 + • Added ShardRegionProxy support to Akka.Cluster.Hosting +• Added DistributedPubSub support to Akka.Cluster.Hosting