Class ShardStrategyFactory
java.lang.Object
services.moleculer.service.MoleculerComponent
services.moleculer.strategy.StrategyFactory
services.moleculer.strategy.ArrayBasedStrategyFactory
services.moleculer.strategy.ShardStrategyFactory
- All Implemented Interfaces:
MoleculerLifecycle
Sharding invocation strategy factory. Using consistent-hashing.
More info: https://www.toptal.com/big-data/consistent-hashing
More info: https://www.toptal.com/big-data/consistent-hashing
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intSize of the memory cache (0 = disabled)Default hash function (MD5).protected IntegerRing size (optional)protected StringShard key's path (eg.protected intNumber of virtual nodesFields inherited from class ArrayBasedStrategyFactory
preferLocalFields inherited from class MoleculerComponent
broker, logger, name -
Constructor Summary
ConstructorsConstructorDescriptionConstructor that calls for service based primarily on its own (hash-based) logic.ShardStrategyFactory(boolean preferLocal) Constructor that can be configured to use local services if possible.ShardStrategyFactory(boolean preferLocal, String shardKey) Constructor that can be configured to use local services if possible.ShardStrategyFactory(String shardKey) Constructor that can be configured to use local services if possible. -
Method Summary
Modifier and TypeMethodDescriptioncreate()intgetHash()intvoidsetCacheSize(int cacheSize) voidvoidsetRingSize(Integer ringSize) voidsetShardKey(String shardKey) voidsetVnodes(int vnodes) Methods inherited from class ArrayBasedStrategyFactory
isPreferLocal, setPreferLocal
-
Field Details
-
shardKey
Shard key's path (eg. "userID", "user.email", "#key", etc.) -
vnodes
protected int vnodesNumber of virtual nodes -
ringSize
Ring size (optional) -
cacheSize
protected int cacheSizeSize of the memory cache (0 = disabled) -
hash
-
-
Constructor Details
-
ShardStrategyFactory
public ShardStrategyFactory()Constructor that calls for service based primarily on its own (hash-based) logic. Does not matter if the service is available locally. -
ShardStrategyFactory
public ShardStrategyFactory(boolean preferLocal) Constructor that can be configured to use local services if possible.- Parameters:
preferLocal- invoke local actions if possible
-
ShardStrategyFactory
Constructor that can be configured to use local services if possible.- Parameters:
shardKey- Shard key's path (eg. "userID", "user.email", "#key", etc.)
-
ShardStrategyFactory
Constructor that can be configured to use local services if possible.- Parameters:
preferLocal- invoke local actions if possibleshardKey- Shard key's path (eg. "userID", "user.email", "#key", etc.)
-
-
Method Details
-
create
- Specified by:
createin classStrategyFactory
-
getShardKey
-
setShardKey
-
getVnodes
public int getVnodes() -
setVnodes
public void setVnodes(int vnodes) -
getRingSize
-
setRingSize
-
getCacheSize
public int getCacheSize() -
setCacheSize
public void setCacheSize(int cacheSize) -
getHash
-
setHash
-