Skip to content

Akka based id generation service with the same algorithm with Twitter Snowflake

License

Notifications You must be signed in to change notification settings

TanUkkii007/reactive-snowflake

Repository files navigation

reactive-snowflake

Akka based id generation service with the same algorithm with Twitter Snowflake

ID format

Same as Snowflake.

Usage

val dcId1 = DatacenterId(1L)
val workerId1 = WorkerId(1L)

val idWorker = system.actorOf(IdWorker.props(dcId1, workerId1))

idWorker ! GenerateId(testActor)

expectMsgType[IdGenerated]

Cluster Support

To automatically manage workerId you can use Akka cluster shardhing.

val datacenterId = 0x01

val idRouter = ClusterSharding(system).shardRegion(ShardedIdRouter.shardName)

val client = system.actorOf(IdClient.props(datacenterId, idRouter))

client.ask(IdClientProtocol.GenerateId).mapTo[IdGenerated].foreach(println)

About

Akka based id generation service with the same algorithm with Twitter Snowflake

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages