Record Class MessageType

java.lang.Object
java.lang.Record
org.axonframework.messaging.core.MessageType
Record Components:
qualifiedName - The QualifiedName of this MessageType.
version - the version of this MessageType.

public record MessageType(QualifiedName qualifiedName, String version) extends Record
Record combining a qualified name and version.

The QualifiedName is useful to provide clear names to Messages, MessageHandlers, and other components that require naming.

When you do not require a version for typing, consider using the QualifiedName directly instead.

Since:
5.0.0
Author:
Allard Buijze, Mateusz Nowak, Steven van Beelen
  • Field Details

    • DEFAULT_VERSION

      public static final String DEFAULT_VERSION
      The default version of a MessageType when none is given. Set to 0.0.1.
      See Also:
  • Constructor Details

    • MessageType

      public MessageType(QualifiedName qualifiedName, String version)
      Compact constructor validating that the given qualifiedName is non-null.
    • MessageType

      public MessageType(QualifiedName name)
      A MessageType constructor setting the version to null.
      Parameters:
      name - The QualifiedName of this MessageType.
    • MessageType

      public MessageType(String qualifiedName)
      A MessageType constructor using the given qualifiedName invoking the QualifiedName(String) constructor. The version is fixed to null.
      Parameters:
      qualifiedName - The qualifiedName for the QualifiedName for the MessageType under construction.
    • MessageType

      public MessageType(String qualifiedName, String version)
      A MessageType constructor using the given qualifiedName to invoke the QualifiedName(String) constructor to derive the qualifiedName for this MessageType.
      Parameters:
      qualifiedName - The qualified qualifiedName used to invoke QualifiedName(String) constructor for the MessageType under construction.
      version - The version for the MessageType under construction.
    • MessageType

      public MessageType(String namespace, String localName, String version)
      A MessageType constructor using the given namespace and localName to invoke the QualifiedName(String, String) constructor to derive the qualifiedName for this MessageType.
      Parameters:
      namespace - The namespace used to invoke QualifiedName(String, String) constructor for the MessageType under construction.
      localName - The local qualifiedName used to invoke QualifiedName(String, String) constructor for the MessageType under construction.
      version - The version for the MessageType under construction.
    • MessageType

      public MessageType(Class<?> clazz, String version)
      A MessageType constructor using the given clazz to invoke the QualifiedName(Class) constructor to derive the qualifiedName for this MessageType.
      Parameters:
      clazz - The Class used to invoke QualifiedName(Class) constructor for the MessageType under construction.
      version - The version for the MessageType under construction.
    • MessageType

      public MessageType(Class<?> clazz)
      A MessageType constructor using the given clazz to invoke the QualifiedName(Class) constructor to derive the qualifiedName for this MessageType. The version is fixed to null.
      Parameters:
      clazz - The Class used to invoke QualifiedName(Class) constructor for the MessageType under construction.
  • Method Details

    • name

      public String name()
      Returns the outcome QualifiedName.name() of this MessageType's QualifiedName.
      Returns:
      The outcome QualifiedName.name() of this MessageType's QualifiedName.
    • fromString

      public static MessageType fromString(String messageTypeString)
      Reconstruct a MessageType based on the output of toString().

      The output of MessageType#toString() is a concatenation of the qualifiedName() and version(), split by means of a hashtag (#).

      Thus, if the given String equals "my.context.BusinessName#1.0.5", the #qualifiedName() is set to a QualifiedName of "my.context.BusinessName" and the version() is set to "1.0.5".

      Parameters:
      messageTypeString - The output of toString(), given to reconstruct it into a MessageType.
      Returns:
      A reconstructed MessageType based on the expected output of toString().
    • toString

      public String toString()
      The output of MessageType#toString() is a concatenation of the qualifiedName() and version(), split by means of a hashtag (#).

      Thus, if #qualifiedName() returns "my.context.BusinessName" and the #version() returns "1.0.5", the result of this operation would be "my.context.BusinessName#1.0.5".

      Specified by:
      toString in class Record
      Returns:
      A combination of the qualifiedName() and version(), separated by a hashtag.
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • qualifiedName

      public QualifiedName qualifiedName()
      Returns the value of the qualifiedName record component.
      Returns:
      the value of the qualifiedName record component
    • version

      public String version()
      Returns the value of the version record component.
      Returns:
      the value of the version record component