GitHub - brainpoint/febs-identify-java: Distributed unique identify like ObjectId
Distributed Unique Identify.
- like objectId, a process can generator id
2^24-1per second. - Container
20chars in id - Use database to assign unique machineId.
How to use
maven config.
<dependency> <groupId>cn.brainpoint</groupId> <artifactId>febs-identify</artifactId> <version>0.0.5</version> </dependency>
Generate the ID using the following code:
import cn.brainpoint.febs.identify.*; String uniqueId = Identify.nextId();
Initialize
import cn.brainpoint.febs.identify.*; Identify.initialize(new IdentifyCfg( "mysql", "localhost:3306/xx", "username", "password", ));
Use database to assign unique machineId. It will use '_distribute_machineId' to named table if not specify a table name.
This method can be invoked multiple times in response to dynamic changes to the application configuration.
Generate a New Id
String id = Identify.nextId();
Valid Id
assert Identify.isValid(id);