Class ShardStrategyFactory

All Implemented Interfaces:
MoleculerLifecycle

public class ShardStrategyFactory extends ArrayBasedStrategyFactory
Sharding invocation strategy factory. Using consistent-hashing.
More info: https://www.toptal.com/big-data/consistent-hashing
See Also:
  • Field Details

    • shardKey

      protected String shardKey
      Shard key's path (eg. "userID", "user.email", "#key", etc.)
    • vnodes

      protected int vnodes
      Number of virtual nodes
    • ringSize

      protected Integer ringSize
      Ring size (optional)
    • cacheSize

      protected int cacheSize
      Size of the memory cache (0 = disabled)
    • hash

      protected Function<String,Long> hash
      Default hash function (MD5).
  • 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

      public ShardStrategyFactory(String shardKey)
      Constructor that can be configured to use local services if possible.
      Parameters:
      shardKey - Shard key's path (eg. "userID", "user.email", "#key", etc.)
    • ShardStrategyFactory

      public ShardStrategyFactory(boolean preferLocal, String shardKey)
      Constructor that can be configured to use local services if possible.
      Parameters:
      preferLocal - invoke local actions if possible
      shardKey - Shard key's path (eg. "userID", "user.email", "#key", etc.)
  • Method Details

    • create

      public <T extends Endpoint> Strategy<T> create()
      Specified by:
      create in class StrategyFactory
    • getShardKey

      public String getShardKey()
    • setShardKey

      public void setShardKey(String shardKey)
    • getVnodes

      public int getVnodes()
    • setVnodes

      public void setVnodes(int vnodes)
    • getRingSize

      public Integer getRingSize()
    • setRingSize

      public void setRingSize(Integer ringSize)
    • getCacheSize

      public int getCacheSize()
    • setCacheSize

      public void setCacheSize(int cacheSize)
    • getHash

      public Function<String,Long> getHash()
    • setHash

      public void setHash(Function<String,Long> hash)