Class SnowflakeProperties

java.lang.Object
com.fayupable.snowflake.jpaspring.SnowflakeProperties

@ConfigurationProperties("snowflake") public class SnowflakeProperties extends Object
Binds to the snowflake prefix in application.yml / application.properties.

Example configuration:


 snowflake:
   node-id: 3
   epoch: 2024-01-01T00:00:00Z
 

nodeId has no valid default on purpose: SnowflakeConfig rejects a negative nodeId, so an application that forgets to set snowflake.node-id fails fast at startup instead of silently colliding with another node that happens to use the same default value.

  • Constructor Details

    • SnowflakeProperties

      public SnowflakeProperties()
  • Method Details

    • getNodeId

      public long getNodeId()
      Returns:
      the node identifier this application instance will embed in every generated id; must be unique across all concurrently running instances sharing the same epoch, or -1 if unconfigured
    • setNodeId

      public void setNodeId(long nodeId)
      Parameters:
      nodeId - the node identifier to embed in every id generated by this application instance; bound from snowflake.node-id
    • getEpoch

      public Instant getEpoch()
      Returns:
      the reference instant (millisecond zero) that generated timestamps are measured from; defaults to 2024-01-01T00:00:00Z if unconfigured
    • setEpoch

      public void setEpoch(Instant epoch)
      Parameters:
      epoch - the reference instant to measure generated timestamps from; bound from snowflake.epoch. Choosing a recent epoch maximizes how many years the 41-bit timestamp field can cover before it overflows.