Identifier Generation
The Axon Framework uses an IdentifierFactory
to generate all identifiers, whether they are for events, commands or queries. The default IdentifierFactory
uses randomly generated java.util.UUID
based identifiers. Although they are safe to use, the process to generate them does not excel in performance.
IdentifierFactory
is an abstract factory that uses Java’s ServiceLoader
(since Java 6) mechanism to find the implementation to use. This means you can create your own implementation of the factory and put the name of the implementation in a file called /META-INF/services/org.axonframework.common.IdentifierFactory
. Java’s ServiceLoader
mechanism will detect that file and attempt to create an instance of the class named inside.
There are a few requirements for the IdentifierFactory
. The implementation must:
-
Have its fully qualified class name as the contents of the
/META-INF/services/org.axonframework.common.IdentifierFactory
file on the classpath, -
have an accessible zero-argument constructor,
-
extend
IdentifierFactory
, -
be accessible by the context classloader of the application or by the classloader that loaded the
IdentifierFactory
class, and must -
Be thread-safe.