Class ClusterSharding
This extension provides sharding functionality of actors in a cluster. The typical use case is when you have many stateful actors that together consume more resources (e.g. memory) than fit on one machine. - Distribution: You need to distribute them across several nodes in the cluster - Location Transparency: You need to interact with them using their logical identifier, without having to care about their physical location in the cluster, which can change over time.
'''Entities''': It could for example be actors representing Aggregate Roots in Domain-Driven Design terminology. Here we call these actors "entities" which typically have persistent (durable) state, but this feature is not limited to persistent state actors.
'''Sharding''': In this context sharding means that actors with an identifier, or entities, can be automatically distributed across multiple nodes in the cluster.
'''ShardRegion''': Each entity actor runs only at one place, and messages can be sent to the entity without requiring the sender to know the location of the destination actor. This is achieved by sending the messages via a ShardRegion actor, provided by this extension. The ShardRegion knows the shard mappings and routes inbound messages to the entity with the entity id. Messages to the entities are always sent via the local ShardRegion. The ShardRegion actor is started on each node in the cluster, or group of nodes tagged with a specific role. The ShardRegion is created with two application specific functions to extract the entity identifier and the shard identifier from incoming messages.
Typical usage of this extension:
1. At system startup on each cluster node by registering the supported entity types with
the Start(String, Props, ClusterShardingSettings, ExtractEntityId, ExtractShardId, IShardAllocationStrategy, Object) method
1. Retrieve the ShardRegion actor for a named entity type with ShardRegion(String)
Settings can be configured as described in the akka.cluster.sharding
section of the reference.conf
.
'''Shard and ShardCoordinator''': A shard is a group of entities that will be managed together. For the first message in a specific shard the ShardRegion requests the location of the shard from a central Akka.Cluster.Sharding.ShardCoordinator. The Akka.Cluster.Sharding.ShardCoordinator decides which ShardRegion owns the shard. The ShardRegion receives the decided home of the shard and if that is the ShardRegion instance itself it will create a local child actor representing the entity and direct all messages for that entity to it. If the shard home is another ShardRegion, instance messages will be forwarded to that ShardRegion instance instead. While resolving the location of a shard, incoming messages for that shard are buffered and later delivered when the shard location is known. Subsequent messages to the resolved shard can be delivered to the target destination immediately without involving the Akka.Cluster.Sharding.ShardCoordinator. To make sure at-most-one instance of a specific entity actor is running somewhere in the cluster it is important that all nodes have the same view of where the shards are located. Therefore the shard allocation decisions are taken by the central Akka.Cluster.Sharding.ShardCoordinator, a cluster singleton, i.e. one instance on the oldest member among all cluster nodes or a group of nodes tagged with a specific role. The oldest member can be determined by IsOlderThan(Member).
'''Shard Rebalancing''':
To be able to use newly added members in the cluster the coordinator facilitates rebalancing
of shards, migrating entities from one node to another. In the rebalance process the
coordinator first notifies all ShardRegion actors that a handoff for a shard has begun.
ShardRegion actors will start buffering incoming messages for that shard, as they do when
shard location is unknown. During the rebalance process the coordinator will not answer any
requests for the location of shards that are being rebalanced, i.e. local buffering will
continue until the handoff is complete. The ShardRegion responsible for the rebalanced shard
will stop all entities in that shard by sending them a PoisonPill. When all entities have
been terminated the ShardRegion owning the entities will acknowledge to the coordinator that
the handoff has completed. Thereafter the coordinator will reply to requests for the location of
the shard, allocate a new home for the shard and then buffered messages in the
ShardRegion actors are delivered to the new location. This means that the state of the entities
are not transferred or migrated. If the state of the entities are of importance it should be
persistent (durable), e.g. with akka-persistence
so that it can be recovered at the new
location.
'''Shard Allocation''': The logic deciding which shards to rebalance is defined in a plugable shard allocation strategy. The default implementation LeastShardAllocationStrategy picks shards for handoff from the ShardRegion with highest number of previously allocated shards. They will then be allocated to the ShardRegion with lowest number of previously allocated shards, i.e. new members in the cluster. This strategy can be replaced by an application
'''Recovery''':
The state of shard locations in the Akka.Cluster.Sharding.ShardCoordinator is stored with akka-distributed-data
or
akka-persistence
to survive failures. When a crashed or unreachable coordinator
node has been removed (via down) from the cluster a new Akka.Cluster.Sharding.ShardCoordinator singleton
actor will take over and the state is recovered. During such a failure period shards
with known location are still available, while messages for new (unknown) shards
are buffered until the new Akka.Cluster.Sharding.ShardCoordinator becomes available.
'''Delivery Semantics''':
As long as a sender uses the same ShardRegion actor to deliver messages to an entity
actor the order of the messages is preserved. As long as the buffer limit is not reached
messages are delivered on a best effort basis, with at-most once delivery semantics,
in the same way as ordinary message sending. Reliable end-to-end messaging, with
at-least-once semantics can be added by using AtLeastOnceDelivery
in akka-persistence
.
Some additional latency is introduced for messages targeted to new or previously unused shards due to the round-trip to the coordinator. Rebalancing of shards may also add latency. This should be considered when designing the application specific shard resolution, e.g. to avoid too fine grained shards.
The ShardRegion actor can also be started in proxy only mode, i.e. it will not host any entities itself, but knows how to delegate messages to the right location.
If the state of the entities are persistent you may stop entities that are not used to reduce memory consumption. This is done by the application specific implementation of the entity actors for example by defining receive timeout (SetReceiveTimeout(Nullable<TimeSpan>)). If a message is already enqueued to the entity when it stops itself the enqueued message in the mailbox will be dropped. To support graceful passivation without losing such messages the entity actor can send Passivate to its parent ShardRegion. The specified wrapped message in Passivate will be sent back to the entity, which is then supposed to stop itself. Incoming messages will be buffered by the ShardRegion between reception of Passivate` and termination of the entity. Such buffered messages are thereafter delivered to a new incarnation of the entity.
Implements
Inherited Members
Namespace: Akka.Cluster.Sharding
Assembly: Akka.Cluster.Sharding.dll
Syntax
public class ClusterSharding : IExtension
Constructors
| Improve this Doc View SourceClusterSharding(ExtendedActorSystem)
Instantiates the Akka.Cluster.Sharding extension for this system.
Declaration
public ClusterSharding(ExtendedActorSystem system)
Parameters
Type | Name | Description |
---|---|---|
ExtendedActorSystem | system | The ActorSystem. |
Properties
| Improve this Doc View SourceSettings
Gets object representing settings for the current cluster sharding plugin.
Declaration
public ClusterShardingSettings Settings { get; }
Property Value
Type | Description |
---|---|
ClusterShardingSettings |
ShardTypeNames
Get all currently defined sharding type names.
Declaration
public ImmutableHashSet<string> ShardTypeNames { get; }
Property Value
Type | Description |
---|---|
System.Collections.Immutable.ImmutableHashSet<String> |
Methods
| Improve this Doc View SourceDefaultConfig()
Default HOCON settings for cluster sharding.
Declaration
public static Config DefaultConfig()
Returns
Type | Description |
---|---|
Config | TBD |
DefaultShardAllocationStrategy(ClusterShardingSettings)
The default IShardAllocationStrategy is configured by least-shard-allocation-strategy
properties.
Declaration
public IShardAllocationStrategy DefaultShardAllocationStrategy(ClusterShardingSettings settings)
Parameters
Type | Name | Description |
---|---|---|
ClusterShardingSettings | settings |
Returns
Type | Description |
---|---|
IShardAllocationStrategy |
Get(ActorSystem)
Retrieves or creates the ClusterSharding extension for the given ActorSystem.
Declaration
public static ClusterSharding Get(ActorSystem system)
Parameters
Type | Name | Description |
---|---|---|
ActorSystem | system | The ActorSystem. |
Returns
Type | Description |
---|---|
ClusterSharding | The singleton instances of the ClusterSharding extension associated with this ActorSystem. |
ShardRegion(String)
Retrieve the actor reference of the ShardRegion actor responsible for the named entity type. The entity type must be registered with the Start(String, Props, ClusterShardingSettings, ExtractEntityId, ExtractShardId, IShardAllocationStrategy, Object) or Akka.Cluster.Sharding.ClusterShardingGuardian.StartProxy method before it can be used here. Messages to the entity is always sent via the ShardRegion.
Declaration
public IActorRef ShardRegion(string typeName)
Parameters
Type | Name | Description |
---|---|---|
String | typeName | TBD |
Returns
Type | Description |
---|---|
IActorRef | TBD |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown when shard region for provided |
ShardRegionProxy(String)
Retrieve the actor reference of the ShardRegion actor that will act as a proxy to the named entity type running in another data center. A proxy within the same data center can be accessed with ShardRegion instead of this method. The entity type must be registered with the Akka.Cluster.Sharding.ClusterShardingGuardian.StartProxy method before it can be used here. Messages to the entity is always sent via the ShardRegion.
Declaration
public IActorRef ShardRegionProxy(string typeName)
Parameters
Type | Name | Description |
---|---|---|
String | typeName |
Returns
Type | Description |
---|---|
IActorRef |
Start(String, Props, ClusterShardingSettings, ExtractEntityId, ExtractShardId)
Register a named entity type by defining the Props of the entity actor and functions to extract entity and shard identifier from messages. The ShardRegion actor for this type can later be retrieved with the ShardRegion(String) method.
This method will start a ShardRegion(String) in proxy mode when there is no match between the roles of the current cluster node and the role specified in ClusterShardingSettings passed to this method.
Some settings can be configured as described in the akka.cluster.sharding
section
of the reference.conf
.
Declaration
[Obsolete("Use one of the overloads that accepts an IMessageExtractor instead")]
public IActorRef Start(string typeName, Props entityProps, ClusterShardingSettings settings, ExtractEntityId extractEntityId, ExtractShardId extractShardId)
Parameters
Type | Name | Description |
---|---|---|
String | typeName | The name of the entity type |
Props | entityProps | The Props of the entity actors that will be created by the ShardRegion |
ClusterShardingSettings | settings | Configuration settings, see ClusterShardingSettings |
ExtractEntityId | extractEntityId | 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 |
ExtractShardId | extractShardId | Function to determine the shard id for an incoming message, only messages
that passed the |
Returns
Type | Description |
---|---|
IActorRef | The actor ref of the ShardRegion that is to be responsible for the shard. |
Exceptions
Type | Condition |
---|---|
IllegalStateException | This exception is thrown when the cluster member doesn't have the role specified in |
Start(String, Props, ClusterShardingSettings, ExtractEntityId, ExtractShardId, IShardAllocationStrategy, Object)
Register a named entity type by defining the Props of the entity actor and functions to extract entity and shard identifier from messages. The ShardRegion actor for this type can later be retrieved with the ShardRegion(String) method.
This method will start a ShardRegion(String) in proxy mode when there is no match between the roles of the current cluster node and the role specified in ClusterShardingSettings passed to this method.
Some settings can be configured as described in the akka.cluster.sharding
section
of the reference.conf
.
Declaration
[Obsolete("Use one of the overloads that accepts an IMessageExtractor instead")]
public IActorRef Start(string typeName, Props entityProps, ClusterShardingSettings settings, ExtractEntityId extractEntityId, ExtractShardId extractShardId, IShardAllocationStrategy allocationStrategy, object handOffStopMessage)
Parameters
Type | Name | Description |
---|---|---|
String | typeName | The name of the entity type |
Props | entityProps | The Props of the entity actors that will be created by the ShardRegion |
ClusterShardingSettings | settings | Configuration settings, see ClusterShardingSettings |
ExtractEntityId | extractEntityId | 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 |
ExtractShardId | extractShardId | Function to determine the shard id for an incoming message, only messages
that passed the |
IShardAllocationStrategy | allocationStrategy | Possibility to use a custom shard allocation and rebalancing logic |
Object | handOffStopMessage | The message that will be sent to entities when they are to be stopped for a rebalance or graceful shutdown of a ShardRegion, e.g. PoisonPill. |
Returns
Type | Description |
---|---|
IActorRef | The actor ref of the ShardRegion that is to be responsible for the shard. |
Exceptions
Type | Condition |
---|---|
IllegalStateException | This exception is thrown when the cluster member doesn't have the role specified in |
Start(String, Props, ClusterShardingSettings, IMessageExtractor)
Register a named entity type by defining the Props of the entity actor and functions to extract entity and shard identifier from messages. The ShardRegion actor for this type can later be retrieved with the ShardRegion(String) method.
This method will start a ShardRegion(String) in proxy mode when there is no match between the roles of the current cluster node and the role specified in ClusterShardingSettings passed to this method.
Some settings can be configured as described in the akka.cluster.sharding
section
of the reference.conf
.
Declaration
public IActorRef Start(string typeName, Props entityProps, ClusterShardingSettings settings, IMessageExtractor messageExtractor)
Parameters
Type | Name | Description |
---|---|---|
String | typeName | The name of the entity type |
Props | entityProps | The Props of the entity actors that will be created by the ShardRegion |
ClusterShardingSettings | settings | Configuration settings, see ClusterShardingSettings |
IMessageExtractor | messageExtractor | Functions to extract the entity id, shard id, and the message to send to the entity from the incoming message. |
Returns
Type | Description |
---|---|
IActorRef | The actor ref of the ShardRegion that is to be responsible for the shard. |
Exceptions
Type | Condition |
---|---|
IllegalStateException | This exception is thrown when the cluster member doesn't have the role specified in |
Start(String, Props, ClusterShardingSettings, IMessageExtractor, IShardAllocationStrategy, Object)
Register a named entity type by defining the Props of the entity actor and functions to extract entity and shard identifier from messages. The ShardRegion actor for this type can later be retrieved with the ShardRegion(String) method.
This method will start a ShardRegion(String) in proxy mode when there is no match between the roles of the current cluster node and the role specified in ClusterShardingSettings passed to this method.
Some settings can be configured as described in the akka.cluster.sharding
section
of the reference.conf
.
Declaration
public IActorRef Start(string typeName, Props entityProps, ClusterShardingSettings settings, IMessageExtractor messageExtractor, IShardAllocationStrategy allocationStrategy, object handOffStopMessage)
Parameters
Type | Name | Description |
---|---|---|
String | typeName | The name of the entity type |
Props | entityProps | The Props of the entity actors that will be created by the ShardRegion |
ClusterShardingSettings | settings | Configuration settings, see ClusterShardingSettings |
IMessageExtractor | messageExtractor | Functions to extract the entity id, shard id, and the message to send to the entity from the incoming message. |
IShardAllocationStrategy | allocationStrategy | Possibility to use a custom shard allocation and rebalancing logic |
Object | handOffStopMessage | The message that will be sent to entities when they are to be stopped for a rebalance or graceful shutdown of a ShardRegion, e.g. PoisonPill. |
Returns
Type | Description |
---|---|
IActorRef | The actor ref of the ShardRegion that is to be responsible for the shard. |
Exceptions
Type | Condition |
---|---|
IllegalStateException | This exception is thrown when the cluster member doesn't have the role specified in |
Start(String, Func<String, Props>, ClusterShardingSettings, ExtractEntityId, ExtractShardId)
Register a named entity type by defining the Props of the entity actor and functions to extract entity and shard identifier from messages. The ShardRegion actor for this type can later be retrieved with the ShardRegion(String) method.
This method will start a ShardRegion(String) in proxy mode when there is no match between the roles of the current cluster node and the role specified in ClusterShardingSettings passed to this method.
Some settings can be configured as described in the akka.cluster.sharding
section
of the reference.conf
.
Declaration
[Obsolete("Use one of the overloads that accepts an IMessageExtractor instead")]
public IActorRef Start(string typeName, Func<string, Props> entityPropsFactory, ClusterShardingSettings settings, ExtractEntityId extractEntityId, ExtractShardId extractShardId)
Parameters
Type | Name | Description |
---|---|---|
String | typeName | The name of the entity type |
Func<String, Props> | entityPropsFactory | Function that, given an entity id, returns the Props of the entity actors that will be created by the ShardRegion |
ClusterShardingSettings | settings | Configuration settings, see ClusterShardingSettings |
ExtractEntityId | extractEntityId | 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 |
ExtractShardId | extractShardId | Function to determine the shard id for an incoming message, only messages
that passed the |
Returns
Type | Description |
---|---|
IActorRef | The actor ref of the ShardRegion that is to be responsible for the shard. |
Exceptions
Type | Condition |
---|---|
IllegalStateException | This exception is thrown when the cluster member doesn't have the role specified in |
Start(String, Func<String, Props>, ClusterShardingSettings, ExtractEntityId, ExtractShardId, IShardAllocationStrategy, Object)
Register a named entity type by defining the Props of the entity actor and functions to extract entity and shard identifier from messages. The ShardRegion actor for this type can later be retrieved with the ShardRegion(String) method.
This method will start a ShardRegion(String) in proxy mode when there is no match between the roles of the current cluster node and the role specified in ClusterShardingSettings passed to this method.
Some settings can be configured as described in the akka.cluster.sharding
section
of the reference.conf
.
Declaration
[Obsolete("Use one of the overloads that accepts an IMessageExtractor instead")]
public IActorRef Start(string typeName, Func<string, Props> entityPropsFactory, ClusterShardingSettings settings, ExtractEntityId extractEntityId, ExtractShardId extractShardId, IShardAllocationStrategy allocationStrategy, object handOffStopMessage)
Parameters
Type | Name | Description |
---|---|---|
String | typeName | The name of the entity type |
Func<String, Props> | entityPropsFactory | Function that, given an entity id, returns the Props of the entity actors that will be created by the ShardRegion |
ClusterShardingSettings | settings | Configuration settings, see ClusterShardingSettings |
ExtractEntityId | extractEntityId | 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 |
ExtractShardId | extractShardId | Function to determine the shard id for an incoming message, only messages
that passed the |
IShardAllocationStrategy | allocationStrategy | Possibility to use a custom shard allocation and rebalancing logic |
Object | handOffStopMessage | The message that will be sent to entities when they are to be stopped for a rebalance or graceful shutdown of a ShardRegion, e.g. PoisonPill. |
Returns
Type | Description |
---|---|
IActorRef | The actor ref of the ShardRegion that is to be responsible for the shard. |
Exceptions
Type | Condition |
---|---|
IllegalStateException | This exception is thrown when the cluster member doesn't have the role specified in |
Start(String, Func<String, Props>, ClusterShardingSettings, IMessageExtractor)
Register a named entity type by defining the Props of the entity actor and functions to extract entity and shard identifier from messages. The ShardRegion actor for this type can later be retrieved with the ShardRegion(String) method.
This method will start a ShardRegion(String) in proxy mode when there is no match between the roles of the current cluster node and the role specified in ClusterShardingSettings passed to this method.
Some settings can be configured as described in the akka.cluster.sharding
section
of the reference.conf
.
Declaration
public IActorRef Start(string typeName, Func<string, Props> entityPropsFactory, ClusterShardingSettings settings, IMessageExtractor messageExtractor)
Parameters
Type | Name | Description |
---|---|---|
String | typeName | The name of the entity type |
Func<String, Props> | entityPropsFactory | Function that, given an entity id, returns the Props of the entity actors that will be created by the ShardRegion |
ClusterShardingSettings | settings | Configuration settings, see ClusterShardingSettings |
IMessageExtractor | messageExtractor | Functions to extract the entity id, shard id, and the message to send to the entity from the incoming message. |
Returns
Type | Description |
---|---|
IActorRef | The actor ref of the ShardRegion that is to be responsible for the shard. |
Exceptions
Type | Condition |
---|---|
IllegalStateException | This exception is thrown when the cluster member doesn't have the role specified in |
Start(String, Func<String, Props>, ClusterShardingSettings, IMessageExtractor, IShardAllocationStrategy, Object)
Register a named entity type by defining the Props of the entity actor and functions to extract entity and shard identifier from messages. The ShardRegion actor for this type can later be retrieved with the ShardRegion(String) method.
This method will start a ShardRegion(String) in proxy mode when there is no match between the roles of the current cluster node and the role specified in ClusterShardingSettings passed to this method.
Some settings can be configured as described in the akka.cluster.sharding
section
of the reference.conf
.
Declaration
public IActorRef Start(string typeName, Func<string, Props> entityPropsFactory, ClusterShardingSettings settings, IMessageExtractor messageExtractor, IShardAllocationStrategy allocationStrategy, object handOffStopMessage)
Parameters
Type | Name | Description |
---|---|---|
String | typeName | The name of the entity type |
Func<String, Props> | entityPropsFactory | Function that, given an entity id, returns the Props of the entity actors that will be created by the ShardRegion |
ClusterShardingSettings | settings | Configuration settings, see ClusterShardingSettings |
IMessageExtractor | messageExtractor | Functions to extract the entity id, shard id, and the message to send to the entity from the incoming message. |
IShardAllocationStrategy | allocationStrategy | Possibility to use a custom shard allocation and rebalancing logic |
Object | handOffStopMessage | The message that will be sent to entities when they are to be stopped for a rebalance or graceful shutdown of a ShardRegion, e.g. PoisonPill. |
Returns
Type | Description |
---|---|
IActorRef | The actor ref of the ShardRegion that is to be responsible for the shard. |
Exceptions
Type | Condition |
---|---|
IllegalStateException | This exception is thrown when the cluster member doesn't have the role specified in |
StartAsync(String, Props, ClusterShardingSettings, ExtractEntityId, ExtractShardId)
Register a named entity type by defining the Props of the entity actor and functions to extract entity and shard identifier from messages. The ShardRegion actor for this type can later be retrieved with the ShardRegion(String) method.
This method will start a ShardRegion(String) in proxy mode when there is no match between the roles of the current cluster node and the role specified in ClusterShardingSettings passed to this method.
Some settings can be configured as described in the akka.cluster.sharding
section
of the reference.conf
.
Declaration
[Obsolete("Use one of the overloads that accepts an IMessageExtractor instead")]
public Task<IActorRef> StartAsync(string typeName, Props entityProps, ClusterShardingSettings settings, ExtractEntityId extractEntityId, ExtractShardId extractShardId)
Parameters
Type | Name | Description |
---|---|---|
String | typeName | The name of the entity type |
Props | entityProps | The Props of the entity actors that will be created by the ShardRegion |
ClusterShardingSettings | settings | Configuration settings, see ClusterShardingSettings |
ExtractEntityId | extractEntityId | 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 |
ExtractShardId | extractShardId | Function to determine the shard id for an incoming message, only messages
that passed the |
Returns
Type | Description |
---|---|
Task<IActorRef> | The actor ref of the ShardRegion that is to be responsible for the shard. |
Exceptions
Type | Condition |
---|---|
IllegalStateException | This exception is thrown when the cluster member doesn't have the role specified in |
StartAsync(String, Props, ClusterShardingSettings, ExtractEntityId, ExtractShardId, IShardAllocationStrategy, Object)
Register a named entity type by defining the Props of the entity actor and functions to extract entity and shard identifier from messages. The ShardRegion actor for this type can later be retrieved with the ShardRegion(String) method.
This method will start a ShardRegion(String) in proxy mode when there is no match between the roles of the current cluster node and the role specified in ClusterShardingSettings passed to this method.
Some settings can be configured as described in the akka.cluster.sharding
section
of the reference.conf
.
Declaration
[Obsolete("Use one of the overloads that accepts an IMessageExtractor instead")]
public Task<IActorRef> StartAsync(string typeName, Props entityProps, ClusterShardingSettings settings, ExtractEntityId extractEntityId, ExtractShardId extractShardId, IShardAllocationStrategy allocationStrategy, object handOffStopMessage)
Parameters
Type | Name | Description |
---|---|---|
String | typeName | The name of the entity type |
Props | entityProps | The Props of the entity actors that will be created by the ShardRegion |
ClusterShardingSettings | settings | Configuration settings, see ClusterShardingSettings |
ExtractEntityId | extractEntityId | 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 |
ExtractShardId | extractShardId | Function to determine the shard id for an incoming message, only messages
that passed the |
IShardAllocationStrategy | allocationStrategy | Possibility to use a custom shard allocation and rebalancing logic |
Object | handOffStopMessage | The message that will be sent to entities when they are to be stopped for a rebalance or graceful shutdown of a ShardRegion, e.g. PoisonPill. |
Returns
Type | Description |
---|---|
Task<IActorRef> | The actor ref of the ShardRegion that is to be responsible for the shard. |
Exceptions
Type | Condition |
---|---|
IllegalStateException | This exception is thrown when the cluster member doesn't have the role specified in |
StartAsync(String, Props, ClusterShardingSettings, IMessageExtractor)
Register a named entity type by defining the Props of the entity actor and functions to extract entity and shard identifier from messages. The ShardRegion actor for this type can later be retrieved with the ShardRegion(String) method.
This method will start a ShardRegion(String) in proxy mode when there is no match between the roles of the current cluster node and the role specified in ClusterShardingSettings passed to this method.
Some settings can be configured as described in the akka.cluster.sharding
section
of the reference.conf
.
Declaration
public Task<IActorRef> StartAsync(string typeName, Props entityProps, ClusterShardingSettings settings, IMessageExtractor messageExtractor)
Parameters
Type | Name | Description |
---|---|---|
String | typeName | The name of the entity type |
Props | entityProps | The Props of the entity actors that will be created by the ShardRegion |
ClusterShardingSettings | settings | Configuration settings, see ClusterShardingSettings |
IMessageExtractor | messageExtractor | Functions to extract the entity id, shard id, and the message to send to the entity from the incoming message. |
Returns
Type | Description |
---|---|
Task<IActorRef> | The actor ref of the ShardRegion that is to be responsible for the shard. |
Exceptions
Type | Condition |
---|---|
IllegalStateException | This exception is thrown when the cluster member doesn't have the role specified in |
StartAsync(String, Props, ClusterShardingSettings, IMessageExtractor, IShardAllocationStrategy, Object)
Register a named entity type by defining the Props of the entity actor and functions to extract entity and shard identifier from messages. The ShardRegion actor for this type can later be retrieved with the ShardRegion(String) method.
This method will start a ShardRegion(String) in proxy mode when there is no match between the roles of the current cluster node and the role specified in ClusterShardingSettings passed to this method.
Some settings can be configured as described in the akka.cluster.sharding
section
of the reference.conf
.
Declaration
public Task<IActorRef> StartAsync(string typeName, Props entityProps, ClusterShardingSettings settings, IMessageExtractor messageExtractor, IShardAllocationStrategy allocationStrategy, object handOffStopMessage)
Parameters
Type | Name | Description |
---|---|---|
String | typeName | The name of the entity type |
Props | entityProps | The Props of the entity actors that will be created by the ShardRegion |
ClusterShardingSettings | settings | Configuration settings, see ClusterShardingSettings |
IMessageExtractor | messageExtractor | Functions to extract the entity id, shard id, and the message to send to the entity from the incoming message. |
IShardAllocationStrategy | allocationStrategy | Possibility to use a custom shard allocation and rebalancing logic |
Object | handOffStopMessage | The message that will be sent to entities when they are to be stopped for a rebalance or graceful shutdown of a ShardRegion, e.g. PoisonPill. |
Returns
Type | Description |
---|---|
Task<IActorRef> | The actor ref of the ShardRegion that is to be responsible for the shard. |
Exceptions
Type | Condition |
---|---|
IllegalStateException | This exception is thrown when the cluster member doesn't have the role specified in |
StartAsync(String, Func<String, Props>, ClusterShardingSettings, ExtractEntityId, ExtractShardId)
Register a named entity type by defining the Props of the entity actor and functions to extract entity and shard identifier from messages. The ShardRegion actor for this type can later be retrieved with the ShardRegion(String) method.
This method will start a ShardRegion(String) in proxy mode when there is no match between the roles of the current cluster node and the role specified in ClusterShardingSettings passed to this method.
Some settings can be configured as described in the akka.cluster.sharding
section
of the reference.conf
.
Declaration
[Obsolete("Use one of the overloads that accepts an IMessageExtractor instead")]
public Task<IActorRef> StartAsync(string typeName, Func<string, Props> entityPropsFactory, ClusterShardingSettings settings, ExtractEntityId extractEntityId, ExtractShardId extractShardId)
Parameters
Type | Name | Description |
---|---|---|
String | typeName | The name of the entity type |
Func<String, Props> | entityPropsFactory | Function that, given an entity id, returns the Props of the entity actors that will be created by the ShardRegion |
ClusterShardingSettings | settings | Configuration settings, see ClusterShardingSettings |
ExtractEntityId | extractEntityId | 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 |
ExtractShardId | extractShardId | Function to determine the shard id for an incoming message, only messages
that passed the |
Returns
Type | Description |
---|---|
Task<IActorRef> | The actor ref of the ShardRegion that is to be responsible for the shard. |
Exceptions
Type | Condition |
---|---|
IllegalStateException | This exception is thrown when the cluster member doesn't have the role specified in |
StartAsync(String, Func<String, Props>, ClusterShardingSettings, ExtractEntityId, ExtractShardId, IShardAllocationStrategy, Object)
Register a named entity type by defining the Props of the entity actor and functions to extract entity and shard identifier from messages. The ShardRegion actor for this type can later be retrieved with the ShardRegion(String) method.
This method will start a ShardRegion(String) in proxy mode when there is no match between the roles of the current cluster node and the role specified in ClusterShardingSettings passed to this method.
Some settings can be configured as described in the akka.cluster.sharding
section
of the reference.conf
.
Declaration
[Obsolete("Use one of the overloads that accepts an IMessageExtractor instead")]
public Task<IActorRef> StartAsync(string typeName, Func<string, Props> entityPropsFactory, ClusterShardingSettings settings, ExtractEntityId extractEntityId, ExtractShardId extractShardId, IShardAllocationStrategy allocationStrategy, object handOffStopMessage)
Parameters
Type | Name | Description |
---|---|---|
String | typeName | The name of the entity type |
Func<String, Props> | entityPropsFactory | Function that, given an entity id, returns the Props of the entity actors that will be created by the ShardRegion |
ClusterShardingSettings | settings | Configuration settings, see ClusterShardingSettings |
ExtractEntityId | extractEntityId | 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 |
ExtractShardId | extractShardId | Function to determine the shard id for an incoming message, only messages
that passed the |
IShardAllocationStrategy | allocationStrategy | Possibility to use a custom shard allocation and rebalancing logic |
Object | handOffStopMessage | The message that will be sent to entities when they are to be stopped for a rebalance or graceful shutdown of a ShardRegion, e.g. PoisonPill. |
Returns
Type | Description |
---|---|
Task<IActorRef> | The actor ref of the ShardRegion that is to be responsible for the shard. |
Exceptions
Type | Condition |
---|---|
IllegalStateException | This exception is thrown when the cluster member doesn't have the role specified in |
StartAsync(String, Func<String, Props>, ClusterShardingSettings, IMessageExtractor)
Register a named entity type by defining the Props of the entity actor and functions to extract entity and shard identifier from messages. The ShardRegion actor for this type can later be retrieved with the ShardRegion(String) method.
This method will start a ShardRegion(String) in proxy mode when there is no match between the roles of the current cluster node and the role specified in ClusterShardingSettings passed to this method.
Some settings can be configured as described in the akka.cluster.sharding
section
of the reference.conf
.
Declaration
public Task<IActorRef> StartAsync(string typeName, Func<string, Props> entityPropsFactory, ClusterShardingSettings settings, IMessageExtractor messageExtractor)
Parameters
Type | Name | Description |
---|---|---|
String | typeName | The name of the entity type |
Func<String, Props> | entityPropsFactory | Function that, given an entity id, returns the Props of the entity actors that will be created by the ShardRegion |
ClusterShardingSettings | settings | Configuration settings, see ClusterShardingSettings |
IMessageExtractor | messageExtractor | Functions to extract the entity id, shard id, and the message to send to the entity from the incoming message. |
Returns
Type | Description |
---|---|
Task<IActorRef> | The actor ref of the ShardRegion that is to be responsible for the shard. |
Exceptions
Type | Condition |
---|---|
IllegalStateException | This exception is thrown when the cluster member doesn't have the role specified in |
StartAsync(String, Func<String, Props>, ClusterShardingSettings, IMessageExtractor, IShardAllocationStrategy, Object)
Register a named entity type by defining the Props of the entity actor and functions to extract entity and shard identifier from messages. The ShardRegion actor for this type can later be retrieved with the ShardRegion(String) method.
This method will start a ShardRegion(String) in proxy mode when there is no match between the roles of the current cluster node and the role specified in ClusterShardingSettings passed to this method.
Some settings can be configured as described in the akka.cluster.sharding
section
of the reference.conf
.
Declaration
public Task<IActorRef> StartAsync(string typeName, Func<string, Props> entityPropsFactory, ClusterShardingSettings settings, IMessageExtractor messageExtractor, IShardAllocationStrategy allocationStrategy, object handOffStopMessage)
Parameters
Type | Name | Description |
---|---|---|
String | typeName | The name of the entity type |
Func<String, Props> | entityPropsFactory | Function that, given an entity id, returns the Props of the entity actors that will be created by the ShardRegion |
ClusterShardingSettings | settings | Configuration settings, see ClusterShardingSettings |
IMessageExtractor | messageExtractor | Functions to extract the entity id, shard id, and the message to send to the entity from the incoming message. |
IShardAllocationStrategy | allocationStrategy | Possibility to use a custom shard allocation and rebalancing logic |
Object | handOffStopMessage | The message that will be sent to entities when they are to be stopped for a rebalance or graceful shutdown of a ShardRegion, e.g. PoisonPill. |
Returns
Type | Description |
---|---|
Task<IActorRef> | The actor ref of the ShardRegion that is to be responsible for the shard. |
Exceptions
Type | Condition |
---|---|
IllegalStateException | This exception is thrown when the cluster member doesn't have the role specified in |
StartProxy(String, String, ExtractEntityId, ExtractShardId)
Register a named entity type ShardRegion on this node that will run in proxy only mode, i.e. it will delegate messages to other ShardRegion actors on other nodes, but not host any entity actors itself. The ShardRegion actor for this type can later be retrieved with the ShardRegion(String) method.
Some settings can be configured as described in the akka.cluster.sharding
section
of the reference.conf
.
Declaration
[Obsolete("Use one of the overloads that accepts an IMessageExtractor instead")]
public IActorRef StartProxy(string typeName, string role, ExtractEntityId extractEntityId, ExtractShardId extractShardId)
Parameters
Type | Name | Description |
---|---|---|
String | typeName | The name of the entity type. |
String | role | Specifies that this entity type is located on cluster nodes with a specific role. If the role is not specified all nodes in the cluster are used. |
ExtractEntityId | extractEntityId | 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 |
ExtractShardId | extractShardId | Function to determine the shard id for an incoming message, only messages
that passed the |
Returns
Type | Description |
---|---|
IActorRef | The actor ref of the ShardRegion that is to be responsible for the shard. |
StartProxy(String, String, IMessageExtractor)
Register a named entity type ShardRegion on this node that will run in proxy only mode, i.e. it will delegate messages to other ShardRegion actors on other nodes, but not host any entity actors itself. The ShardRegion actor for this type can later be retrieved with the ShardRegion(String) method.
Some settings can be configured as described in the akka.cluster.sharding
section
of the reference.conf
.
Declaration
public IActorRef StartProxy(string typeName, string role, IMessageExtractor messageExtractor)
Parameters
Type | Name | Description |
---|---|---|
String | typeName | The name of the entity type. |
String | role | Specifies that this entity type is located on cluster nodes with a specific role. If the role is not specified all nodes in the cluster are used. |
IMessageExtractor | messageExtractor | Functions to extract the entity id, shard id, and the message to send to the entity from the incoming message. |
Returns
Type | Description |
---|---|
IActorRef | The actor ref of the ShardRegion that is to be responsible for the shard. |
StartProxyAsync(String, String, ExtractEntityId, ExtractShardId)
Register a named entity type ShardRegion on this node that will run in proxy only mode, i.e. it will delegate messages to other ShardRegion actors on other nodes, but not host any entity actors itself. The ShardRegion actor for this type can later be retrieved with the ShardRegion(String) method.
Some settings can be configured as described in the akka.cluster.sharding
section
of the reference.conf
.
Declaration
[Obsolete("Use one of the overloads that accepts an IMessageExtractor instead")]
public Task<IActorRef> StartProxyAsync(string typeName, string role, ExtractEntityId extractEntityId, ExtractShardId extractShardId)
Parameters
Type | Name | Description |
---|---|---|
String | typeName | The name of the entity type. |
String | role | Specifies that this entity type is located on cluster nodes with a specific role. If the role is not specified all nodes in the cluster are used. |
ExtractEntityId | extractEntityId | 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 |
ExtractShardId | extractShardId | Function to determine the shard id for an incoming message, only messages
that passed the |
Returns
Type | Description |
---|---|
Task<IActorRef> | The actor ref of the ShardRegion that is to be responsible for the shard. |
StartProxyAsync(String, String, IMessageExtractor)
Register a named entity type ShardRegion on this node that will run in proxy only mode, i.e. it will delegate messages to other ShardRegion actors on other nodes, but not host any entity actors itself. The ShardRegion actor for this type can later be retrieved with the ShardRegion(String) method.
Some settings can be configured as described in the akka.cluster.sharding
section
of the reference.conf
.
Declaration
public async Task<IActorRef> StartProxyAsync(string typeName, string role, IMessageExtractor messageExtractor)
Parameters
Type | Name | Description |
---|---|---|
String | typeName | The name of the entity type. |
String | role | Specifies that this entity type is located on cluster nodes with a specific role. If the role is not specified all nodes in the cluster are used. |
IMessageExtractor | messageExtractor | Functions to extract the entity id, shard id, and the message to send to the entity from the incoming message. |
Returns
Type | Description |
---|---|
Task<IActorRef> | The actor ref of the ShardRegion that is to be responsible for the shard. |