Class ShardingMessageExtractor<E,M>
java.lang.Object
org.apache.pekko.cluster.sharding.typed.ShardingMessageExtractor<E,M>
- Type Parameters:
E- Possibly an Envelope around the messages accepted by the entity actor, is the same asMif there is no envelope.M- The type of message accepted by the entity actor
- Direct Known Subclasses:
HashCodeMessageExtractor,HashCodeNoEnvelopeMessageExtractor,Murmur2MessageExtractor,Murmur2NoEnvelopeMessageExtractor
Entirely customizable typed message extractor. Prefer
HashCodeMessageExtractor or
HashCodeNoEnvelopeMessageExtractorif possible.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <M> ShardingMessageExtractor<ShardingEnvelope<M>,M> apply(int numberOfShards) Scala API:abstract StringExtract the entity id from an incomingmessage.static <M> ShardingMessageExtractor<M,M> noEnvelope(int numberOfShards, M stopMessage, scala.Function1<M, String> extractEntityId) Scala API: Create a message extractor for a protocol where the entity id is available in each message.abstract StringThe shard identifier for a given entity id.abstract MunwrapMessage(E message) Extract the message to send to the entity from an incomingmessage.
-
Constructor Details
-
ShardingMessageExtractor
public ShardingMessageExtractor()
-
-
Method Details
-
apply
Scala API:Create the default message extractor, using envelopes to identify what entity a message is for and the hashcode of the entityId to decide which shard an entity belongs to.
This is recommended since it does not force details about sharding into the entity protocol
-
noEnvelope
public static <M> ShardingMessageExtractor<M,M> noEnvelope(int numberOfShards, M stopMessage, scala.Function1<M, String> extractEntityId) Scala API: Create a message extractor for a protocol where the entity id is available in each message. -
entityId
Extract the entity id from an incomingmessage. Ifnullis returned the message will beunhandled, i.e. posted asUnhandledmessages on the event stream -
shardId
The shard identifier for a given entity id. Only messages that passed theentityId(E)function will be used as input to this function. -
unwrapMessage
Extract the message to send to the entity from an incomingmessage. Note that the extracted message does not have to be the same as the incoming message to support wrapping in message envelope that is unwrapped before sending to the entity actor.
-