Interface Message


public interface Message
AMQP 1.0 message.
See Also:
  • Method Details

    • messageId

      Object messageId()
      Get message ID.
      Returns:
      the message ID
    • messageIdAsString

      String messageIdAsString()
      Get message ID as a string.
      Returns:
      the message ID as a string
    • messageIdAsLong

      long messageIdAsLong()
      Get message ID as a long.
      Returns:
      the message ID as a long
    • messageIdAsBinary

      byte[] messageIdAsBinary()
      Get message ID as an array of bytes.
      Returns:
      the message ID as an array of bytes
    • messageIdAsUuid

      UUID messageIdAsUuid()
      Get message ID as a UUID.
      Returns:
      the message ID as a UUID
    • correlationId

      Object correlationId()
      Get message correlation ID.
      Returns:
      the message correlation ID
    • correlationIdAsString

      String correlationIdAsString()
      Get message correlation ID as a string.
      Returns:
      the message correlation ID as a string
    • correlationIdAsLong

      long correlationIdAsLong()
      Get message correlation ID as a long.
      Returns:
      the message correlation ID as a long
    • correlationIdAsBinary

      byte[] correlationIdAsBinary()
      Get message correlation ID as an array of bytes.
      Returns:
      the message correlation ID as an array of bytes
    • correlationIdAsUuid

      UUID correlationIdAsUuid()
      Get message correlation ID as a UUID.
      Returns:
      the message correlation ID as a UUID
    • userId

      byte[] userId()
      Get user ID
      Returns:
      the user ID
    • to

      String to()
      Get the to field.
      Returns:
      the to field
    • subject

      String subject()
      Get the subject.
      Returns:
      the subject
    • replyTo

      String replyTo()
      Get the reply-to field.
      Returns:
      the reply-to field
    • messageId

      Message messageId(Object id)
      Set the message ID.
      Parameters:
      id - ID
      Returns:
      the message
    • messageId

      Message messageId(String id)
      Set the message ID (string).
      Parameters:
      id - message ID
      Returns:
      the message
    • messageId

      Message messageId(long id)
      Set the message ID (long).
      Parameters:
      id - message ID
      Returns:
      the message
    • messageId

      Message messageId(byte[] id)
      Set the message ID (array of bytes).
      Parameters:
      id - message ID
      Returns:
      the message
    • messageId

      Message messageId(UUID id)
      Set the message ID (UUID).
      Parameters:
      id - message ID
      Returns:
      the message
    • correlationId

      Message correlationId(Object correlationId)
      Set the message correlation ID.
      Parameters:
      correlationId - correlation ID
      Returns:
      the message
    • correlationId

      Message correlationId(String correlationId)
      Set the message correlation ID (string).
      Parameters:
      correlationId - correlation ID
      Returns:
      the message
    • correlationId

      Message correlationId(long correlationId)
      Set the message correlation ID (long).
      Parameters:
      correlationId - correlation ID
      Returns:
      the message
    • correlationId

      Message correlationId(byte[] correlationId)
      Set the message correlation ID (array of bytes).
      Parameters:
      correlationId - correlation ID
      Returns:
      the message
    • correlationId

      Message correlationId(UUID correlationId)
      Set the message correlation ID (UUID).
      Parameters:
      correlationId - correlation ID
      Returns:
      the message
    • userId

      Message userId(byte[] userId)
      Set the user ID.
      Parameters:
      userId - user ID
      Returns:
      the message
    • to

      Message to(String address)
      Set the to field.

      Prefer using toAddress() to build the target address.

      Parameters:
      address - to address
      Returns:
      the message
      See Also:
    • subject

      Message subject(String subject)
      Set the message subject.
      Parameters:
      subject - message subject
      Returns:
      the message
    • replyTo

      Message replyTo(String replyTo)
      Set the reply-to field.

      Prefer using replyToAddress() to build the reply-to address.

      Parameters:
      replyTo - reply-to field
      Returns:
      the message
      See Also:
    • contentType

      Message contentType(String contentType)
      Set the content-type.
      Parameters:
      contentType - content-type
      Returns:
      the message
    • contentEncoding

      Message contentEncoding(String contentEncoding)
      Set the content-encoding.
      Parameters:
      contentEncoding - content-encoding
      Returns:
      the message
    • absoluteExpiryTime

      Message absoluteExpiryTime(long absoluteExpiryTime)
      Set the expiry time.
      Parameters:
      absoluteExpiryTime - expiry time
      Returns:
      the message
    • creationTime

      Message creationTime(long creationTime)
      Set the creation time.
      Parameters:
      creationTime - creation time
      Returns:
      the message
    • groupId

      Message groupId(String groupID)
      Set the group ID.
      Parameters:
      groupID - group ID
      Returns:
      the message
    • groupSequence

      Message groupSequence(int groupSequence)
      Set the position of the message in its group.
      Parameters:
      groupSequence - group sequence
      Returns:
      the message
    • replyToGroupId

      Message replyToGroupId(String groupId)
      Set the reply-to group ID.
      Parameters:
      groupId - reply-to group ID
      Returns:
      the message
    • contentType

      String contentType()
      Get the content-type.
      Returns:
      the content-type
    • contentEncoding

      String contentEncoding()
      Get the content-encoding.
      Returns:
      the content-encoding
    • absoluteExpiryTime

      long absoluteExpiryTime()
      Get the expiry time.
      Returns:
      the expiry time
    • creationTime

      long creationTime()
      Get the creation time.
      Returns:
      the creation time
    • groupId

      String groupId()
      Get the group ID.
      Returns:
      the group ID
    • groupSequence

      int groupSequence()
      Get the message position in its group.
      Returns:
      the group sequence
    • replyToGroupId

      String replyToGroupId()
      Get the reply-to group ID.
      Returns:
      the reply-to group ID
    • property

      Object property(String key)
      Get the value of an application property.
      Parameters:
      key - property key
      Returns:
      See Also:
    • property

      Message property(String key, boolean value)
      Set an application property.
      Parameters:
      key - property key
      value - property value
      Returns:
      the message
    • property

      Message property(String key, byte value)
      Set an application property.
      Parameters:
      key - property key
      value - property value
      Returns:
      the message
    • property

      Message property(String key, short value)
      Set an application property.
      Parameters:
      key - property key
      value - property value
      Returns:
      the message
    • property

      Message property(String key, int value)
      Set an application property.
      Parameters:
      key - property key
      value - property value
      Returns:
      the message
    • property

      Message property(String key, long value)
      Set an application property.
      Parameters:
      key - property key
      value - property value
      Returns:
      the message
    • propertyUnsigned

      Message propertyUnsigned(String key, byte value)
      Set an application property.
      Parameters:
      key - property key
      value - property value
      Returns:
      the message
    • propertyUnsigned

      Message propertyUnsigned(String key, short value)
      Set an application property.
      Parameters:
      key - property key
      value - property value
      Returns:
      the message
    • propertyUnsigned

      Message propertyUnsigned(String key, int value)
      Set an application property.
      Parameters:
      key - property key
      value - property value
      Returns:
      the message
    • propertyUnsigned

      Message propertyUnsigned(String key, long value)
      Set an application property.
      Parameters:
      key - property key
      value - property value
      Returns:
      the message
    • property

      Message property(String key, float value)
      Set an application property.
      Parameters:
      key - property key
      value - property value
      Returns:
      the message
    • property

      Message property(String key, double value)
      Set an application property.
      Parameters:
      key - property key
      value - property value
      Returns:
      the message
    • propertyDecimal32

      Message propertyDecimal32(String key, BigDecimal value)
      Set an application property.
      Parameters:
      key - property key
      value - property value
      Returns:
      the message
    • propertyDecimal64

      Message propertyDecimal64(String key, BigDecimal value)
      Set an application property.
      Parameters:
      key - property key
      value - property value
      Returns:
      the message
    • propertyDecimal128

      Message propertyDecimal128(String key, BigDecimal value)
      Set an application property.
      Parameters:
      key - property key
      value - property value
      Returns:
      the message
    • property

      Message property(String key, char value)
      Set an application property.
      Parameters:
      key - property key
      value - property value
      Returns:
      the message
    • propertyTimestamp

      Message propertyTimestamp(String key, long value)
      Set an application property.
      Parameters:
      key - property key
      value - property value
      Returns:
      the message
    • property

      Message property(String key, UUID value)
      Set an application property.
      Parameters:
      key - property key
      value - property value
      Returns:
      the message
    • property

      Message property(String key, byte[] value)
      Set an application property.
      Parameters:
      key - property key
      value - property value
      Returns:
      the message
    • property

      Message property(String key, String value)
      Set an application property.
      Parameters:
      key - property key
      value - property value
      Returns:
      the message
    • propertySymbol

      Message propertySymbol(String key, String value)
      Set an application property.
      Parameters:
      key - property key
      value - property value
      Returns:
      the message
    • hasProperty

      boolean hasProperty(String key)
      Check an application property is set.
      Parameters:
      key - property name
      Returns:
      true if set, false otherwise
    • hasProperties

      boolean hasProperties()
      Whether at least one application property is set on the message.
      Returns:
      true if the message has at least one application property, false otherwise
    • removeProperty

      Object removeProperty(String key)
      Remove an application property.
      Parameters:
      key - property key
      Returns:
      the previous property value, if any
    • forEachProperty

      Message forEachProperty(BiConsumer<String,Object> action)
      Iterate over application properties.
      Parameters:
      action - action to execute for each application property
      Returns:
      the message
    • body

      Message body(byte[] body)
      Set the body of the message.
      Parameters:
      body - message body
      Returns:
      the message
    • body

      byte[] body()
      Get the message body as bytes.

      This is a convenience API for byte-oriented payload access. It is intended for message bodies that can be represented as a byte array, such as Data sections and compatible AmqpValue payloads (for example String values converted to UTF-8 bytes).

      For AMQP body types that are not naturally byte-oriented, such as AmqpSequence or typed AmqpValue payloads, use body(Converter) or body(SectionsConverter).

      Returns:
      the message body as bytes
      Throws:
      AmqpException - if the body cannot be represented as bytes
    • body

      <I,O> O body(Message.Converter<I,O> converter)
      Get the message body converted using the specified converter.

      This method provides access to the message body content in its native AMQP 1.0 format, allowing applications to handle non-binary payloads and complex message body structures. According to the AMQP 1.0 message format specification, a message body can contain various section types including AmqpValue, AmqpSequence, and Data sections.

      This method extracts the value from the first body section only and passes it to the converter. For messages with multiple body sections, use body(SectionsConverter) instead.

      The converter input type must match the runtime type of the value exposed by the underlying AMQP implementation for the first body section. For example, applications may receive byte[], String, List<?>, or implementation-specific AMQP types such as Binary.

      If the converter expects a type that does not match the runtime body value type, a ClassCastException may be thrown by the converter invocation.

      Implementation Note: This method exposes values coming from the underlying AMQP implementation (currently Qpid Proton-J2). Applications using this API should treat these values as implementation-coupled runtime types rather than stable library-defined model types. Changes in the underlying implementation may affect the concrete runtime types observed by applications using this API.

      Type Parameters:
      I - the input type expected by the converter (the type of the body section value)
      O - the output type returned by the converter
      Parameters:
      converter - the converter to transform the body section value
      Returns:
      the converted body value
      Throws:
      AmqpException - if an error occurs while accessing the message body
      See Also:
    • body

      <I,O> O body(Message.SectionsConverter<I,O> converter)
      Get the message body with access to all body sections using the specified sections converter.

      This method provides complete access to multi-section message bodies as defined in the AMQP 1.0 message format specification. AMQP 1.0 messages can contain multiple body sections of the same type:

      • Multiple Data sections - Each containing binary data, typically concatenated logically
      • Multiple AmqpSequence sections - Each containing a list of structured values
      • Single AmqpValue section - Containing a single AMQP value of any type

      The converter receives a list of all section values from the message body, allowing applications to process complex multi-section payloads that cannot be handled by the single-section body(Converter) method.

      The converter input type must match the runtime type of each section value exposed by the underlying AMQP implementation. All body sections in a valid AMQP message are expected to be of the same section kind, but applications should still treat the values as implementation exposed runtime objects.

      If the converter expects a type that does not match the runtime section value type, a ClassCastException may be thrown by the converter invocation.

      Implementation Note: This method exposes values coming from the underlying AMQP implementation (currently Qpid Proton-J2). Applications using this API should treat these values as implementation-coupled runtime types rather than stable library-defined model types. Changes in the underlying implementation may affect the concrete runtime types observed by applications using this API.

      Type Parameters:
      I - the input type expected by the converter (the type of each body section value)
      O - the output type returned by the converter
      Parameters:
      converter - the sections converter to transform all body section values
      Returns:
      the converted body value from all sections
      Throws:
      AmqpException - if an error occurs while accessing the message body sections
      See Also:
    • durable

      Message durable(boolean durable)
      Mark the message as durable or not.

      Messages are durable by default, use false to make them explicitly non-durable.

      Durability depends also on the queue messages end up in (e.g. quorum queues and streams always store messages durably).

      Parameters:
      durable - true for a durable message, false for a non-durable message
      Returns:
      the message
    • durable

      boolean durable()
      Whether the message is durable.
      Returns:
      true if durable, false otherwise
      See Also:
    • deliveryCount

      long deliveryCount()
      Get the delivery count of the message.

      The delivery count tracks the number of failed delivery attempts for the message. This value is incremented when a delivery fails (e.g., consumer crashes, message is rejected, or AMQP 1.0 modify disposition with delivery_failed=true). It is not incremented for successful requeues (e.g., nack or AMQP 1.0 modify with delivery_failed=false).

      Returns:
      the delivery count
      Since:
      1.1.0
      See Also:
    • priority

      Message priority(byte priority)
      Set the priority of the message.
      Parameters:
      priority - message priority
      Returns:
      the message
      See Also:
    • priority

      byte priority()
      Get the message priority.
      Returns:
      the message priority
      See Also:
    • ttl

      Message ttl(Duration ttl)
      Set the message TTL.
      Parameters:
      ttl - message TTL
      Returns:
      the message
      See Also:
    • ttl

      Duration ttl()
      Get the message TTL.
      Returns:
      the message TTL
      See Also:
    • firstAcquirer

      boolean firstAcquirer()
      Whether the message may have been acquired by another link.
      Returns:
      true if the message has not been acquired by another link, false if it may have been already acquired by another link
      See Also:
    • annotation

      Object annotation(String key)
      Get the value of a message annotation.
      Parameters:
      key - annotation key
      Returns:
      the annotation value
      See Also:
    • annotation

      Message annotation(String key, Object value)
      Set the value of a message annotation.
      Parameters:
      key - annotation key
      value - annotation value
      Returns:
      the message
      See Also:
    • hasAnnotation

      boolean hasAnnotation(String key)
      Whether a message annotation is set.
      Parameters:
      key - annotation key
      Returns:
      true if the annotation is set, false otherwise
      See Also:
    • hasAnnotations

      boolean hasAnnotations()
      Whether the message has message annotation.
      Returns:
      true if the message has annotations, false otherwise
      See Also:
    • removeAnnotation

      Object removeAnnotation(String key)
      Remove an annotation.
      Parameters:
      key - annotation key
      Returns:
      the previous value of the annotation, if any
      See Also:
    • forEachAnnotation

      Message forEachAnnotation(BiConsumer<String,Object> action)
      Iterate over message annotations.
      Parameters:
      action - action to execute for each message annotation
      Returns:
      the message
    • toAddress

      AddressBuilder for the to() field.
      Returns:
      the address builder
    • replyToAddress

      AddressBuilder for the replyTo() field.
      Returns:
      the address builder