Akka based id generation service with the same algorithm with Twitter Snowflake
Same as Snowflake.
val dcId1 = DatacenterId(1L)
val workerId1 = WorkerId(1L)
val idWorker = system.actorOf(IdWorker.props(dcId1, workerId1))
idWorker ! GenerateId(testActor)
expectMsgType[IdGenerated]
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)