A k-sortable unique ID generation lib using Scala.
Snowflake4s can generate the roughly-sorted 64 bits ids as Long type. The name of this lib was inspired by a project from Twitter called "Snowflake". So, it's using the same encoded ID format as Twitter's Snowflake. But Snowflake4s providing the easier way to use Snowflake schema.
You should add the following dependency.
libraryDependencies += "com.septech" %% "snowflake4s_2.12" % "0.0.1-ALPHA"
Add manual config to application.conf
:
snowflake4s {
twitter { # using Twitter's algorithm
machine_id = 1 # from 1 to 31
worker_id = 1 # from 1 to 31
}
}
to generate id:
val IdGenerator = Snowflake4s.generator
val id = IdGenerator.generate()
You also could bulk generate 10 ids with the following snippet:
val IdGenerator = Snowflake4s.generator
val ids = IdGenerator.bulkGenerate(10)
The Snowflake4s is released under version 2.0 of the Apache License.