Ynn micro-service module for ID allocation. Supported FlakeID and UUID.
$ npm install ynn-ms-idalloc --save
$ npx ynn-ms-idalloc --port=3000
const Ynn = require( 'ynn' );
const app = new Ynn( {
root : __dirname,
modules : {
id : {
path : 'ynn-ms-idalloc',
config : { }
}
}
} );
flake Object
- datacenter (5 bit) - datacenter identifier. It can have values from 0 to 31.
- worker (5 bit) - worker identifier. It can have values from 0 to 31.
- id (10 bit) - gnerator identifier. It can have values from 0 to 1023. It can be provided instead of datacenter and worker identifiers.
- epoch - number used to reduce value of a generated timestamp. Note that this number should not exceed number of milliseconds elapsed since 1 January 1970 00:00:00 UTC. It can be used to generate smaller ids.
Generating SnowFlake ID is using https://github.com/T-PWK/flake-idgen package.
To generate a SnowFlake ID.
To generate UUID version 1
To generate UUID version 3
To generate UUID version 4
Note: While generating UUID v3 and v5, the namespace can be a pre-defined namespace name in [ dns, url, oid, x500 ] defind in RFC4122. For example:
/uuid/v5?name={name}&namespace=url
To generate UUID version 5