Interface MessageId

All Superinterfaces:
Comparable<MessageId>, Serializable
All Known Subinterfaces:
TopicMessageId

@Public @Stable public interface MessageId extends Comparable<MessageId>, Serializable
Opaque unique identifier of a single message

The MessageId can be used to reference a specific message, for example when acknowledging, without having to retain the message content in memory for an extended period of time.

Message ids are Comparable and a bigger message id will imply that a message was published "after" the other one.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final MessageId
    MessageId that represents the oldest message available in the topic.
    static final MessageId
    MessageId that represents the next message published in the topic.
  • Method Summary

    Modifier and Type
    Method
    Description
    static MessageId
    fromByteArray(byte[] data)
    De-serialize a message id from a byte array.
    static MessageId
    fromByteArrayWithTopic(byte[] data, String topicName)
    De-serialize a message id from a byte array with its topic information attached.
    byte[]
    Serialize the message ID into a byte array.

    Methods inherited from interface java.lang.Comparable

    compareTo
  • Field Details

    • earliest

      static final MessageId earliest
      MessageId that represents the oldest message available in the topic.
    • latest

      static final MessageId latest
      MessageId that represents the next message published in the topic.
  • Method Details

    • toByteArray

      byte[] toByteArray()
      Serialize the message ID into a byte array.

      The serialized message id can be stored away and later get deserialized by using fromByteArray(byte[]).

    • fromByteArray

      static MessageId fromByteArray(byte[] data) throws IOException
      De-serialize a message id from a byte array.
      Parameters:
      data - byte array containing the serialized message id
      Returns:
      the de-serialized messageId object
      Throws:
      IOException - if the de-serialization fails
    • fromByteArrayWithTopic

      static MessageId fromByteArrayWithTopic(byte[] data, String topicName) throws IOException
      De-serialize a message id from a byte array with its topic information attached.

      The topic information is needed when acknowledging a MessageId on a consumer that is consuming from multiple topics.

      Parameters:
      data - the byte array with the serialized message id
      topicName - the topic name
      Returns:
      a instance
      Throws:
      IOException - if the de-serialization fails