Identity generator serves as a identity generator. You can also use this module as a guid generator standards.
We have already implemented SnowflakeGuidGenerator
with snowflake algorithm open-sourced
by X (former Twitter), you can also implement a custom guid creations by
implementing com.onixbyte.identity.IdentityGenerator
.
IdentityGenerator<UUID> uuidCreator = (IdentityGenerator<UUID>) UUID::randomUUID;
Assume that you need serial guid creator.
@Component
public class CustomGuidGenerator implementes IdentityGenerator<String> {
public final RedisTemplate<String, Long> serialRedisTemplate;
@Autowired
public CustomGuidGenerator(RedisTemplate<String, Long> serialRedisTemplate) {
this.serialRedisTemplate = serialRedisTemplate;
}
@Override
public String nextId() {
return "SOME_PREFIX" + serialRedisTemplate.opsForValue().get("some_serial_key");
}
}