Class SnowflakeProperties
java.lang.Object
com.fayupable.snowflake.jpaspring.SnowflakeProperties
Binds to the
snowflake prefix in application.yml / application.properties.
Example configuration:
snowflake:
datacenter-id: 1
worker-id: 3
epoch: 2024-01-01T00:00:00Z
datacenterId and workerId have no valid default on purpose:
SnowflakeConfig rejects a negative value
for either, so an application that forgets to set them fails fast at startup
instead of silently colliding with another node that happens to use the same
default value.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlonggetEpoch()longvoidsetDatacenterId(long datacenterId) voidvoidsetWorkerId(long workerId)
-
Constructor Details
-
SnowflakeProperties
public SnowflakeProperties()
-
-
Method Details
-
getDatacenterId
public long getDatacenterId()- Returns:
- the datacenter identifier this application instance will embed in
every generated id; must be unique per physical/logical datacenter
sharing the same
epoch, or -1 if unconfigured
-
setDatacenterId
public void setDatacenterId(long datacenterId) - Parameters:
datacenterId- the datacenter identifier to embed in every id generated by this application instance; bound fromsnowflake.datacenter-id
-
getWorkerId
public long getWorkerId()- Returns:
- the worker identifier this application instance will embed in every
generated id; must be unique across all concurrently running
instances within the same datacenter sharing the same
epoch, or -1 if unconfigured
-
setWorkerId
public void setWorkerId(long workerId) - Parameters:
workerId- the worker identifier to embed in every id generated by this application instance; bound fromsnowflake.worker-id
-
getEpoch
- Returns:
- the reference instant (millisecond zero) that generated timestamps are measured from; defaults to 2024-01-01T00:00:00Z if unconfigured
-
setEpoch
- Parameters:
epoch- the reference instant to measure generated timestamps from; bound fromsnowflake.epoch. Choosing a recent epoch maximizes how many years the 41-bit timestamp field can cover before it overflows.
-