Class MessageProperties

java.lang.Object
org.springframework.amqp.core.MessageProperties
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
StreamMessageProperties

public class MessageProperties extends Object implements Serializable
Message Properties for an AMQP message.
Author:
Mark Fisher, Mark Pollack, Gary Russell, Dmitry Chernyshov, Artem Bilan, Csaba Soti, Raylax Grey, Ngoc Nhan
See Also:
  • Field Details

    • CONTENT_TYPE_BYTES

      public static final String CONTENT_TYPE_BYTES
      See Also:
    • CONTENT_TYPE_TEXT_PLAIN

      public static final String CONTENT_TYPE_TEXT_PLAIN
      See Also:
    • CONTENT_TYPE_SERIALIZED_OBJECT

      public static final String CONTENT_TYPE_SERIALIZED_OBJECT
      See Also:
    • CONTENT_TYPE_JSON

      public static final String CONTENT_TYPE_JSON
      See Also:
    • CONTENT_TYPE_JSON_ALT

      public static final String CONTENT_TYPE_JSON_ALT
      See Also:
    • CONTENT_TYPE_XML

      public static final String CONTENT_TYPE_XML
      See Also:
    • SPRING_BATCH_FORMAT

      public static final String SPRING_BATCH_FORMAT
      See Also:
    • BATCH_FORMAT_LENGTH_HEADER4

      public static final String BATCH_FORMAT_LENGTH_HEADER4
      See Also:
    • SPRING_AUTO_DECOMPRESS

      public static final String SPRING_AUTO_DECOMPRESS
      See Also:
    • DELIVERY_TIME

      public static final String DELIVERY_TIME
      The RabbitMQ 4.4 native message delivery-time header. The value is an absolute Unix timestamp in milliseconds, unlike X_DELAY, which is a relative delay used by the delayed-message-exchange plugin.
      Since:
      4.2
      See Also:
    • X_DELAY

      @Deprecated(since="4.2", forRemoval=true) public static final String X_DELAY
      Deprecated, for removal: This API element is subject to removal in a future version.
      Since 4.2, in favor of DELIVERY_TIME for RabbitMQ 4.4 quorum queues.
      The header used by the delayed-message-exchange plugin.
      See Also:
    • X_DEATH

      public static final String X_DEATH
      See Also:
    • RETRY_COUNT

      public static final String RETRY_COUNT
      The custom header to represent a number of retries a message is republished. In case of server-side DLX, this header contains the value of x-death.count property. When republish is done manually, this header has to be incremented by the application.
      See Also:
    • DEFAULT_CONTENT_TYPE

      public static final String DEFAULT_CONTENT_TYPE
      See Also:
    • DEFAULT_DELIVERY_MODE

      public static final MessageDeliveryMode DEFAULT_DELIVERY_MODE
    • DEFAULT_PRIORITY

      public static final Integer DEFAULT_PRIORITY
    • X_DELAY_MAX

      @Deprecated(since="4.2", forRemoval=true) public static final long X_DELAY_MAX
      Deprecated, for removal: This API element is subject to removal in a future version.
      Since 4.2, for removal with the delayed-message-exchange plugin support.
      The maximum value of x-delay header.
      Since:
      3.1.2
      See Also:
  • Constructor Details

    • MessageProperties

      public MessageProperties()
  • Method Details

    • setHeader

      public void setHeader(String key, Object value)
    • setHeaders

      public void setHeaders(Map<String,Object> headers)
      Set headers.
      Parameters:
      headers - the headers.
      Since:
      2.4.7
    • getHeader

      public <T> @Nullable T getHeader(String headerName)
      Typed getter for a header.
      Type Parameters:
      T - the type.
      Parameters:
      headerName - the header name.
      Returns:
      the header value
      Since:
      2.2
    • getHeaders

      public Map<String, @Nullable Object> getHeaders()
    • setTimestamp

      public void setTimestamp(@Nullable Date timestamp)
    • getTimestamp

      public @Nullable Date getTimestamp()
    • setMessageId

      public void setMessageId(@Nullable String messageId)
    • getMessageId

      public @Nullable String getMessageId()
    • setUserId

      public void setUserId(@Nullable String userId)
    • getUserId

      public @Nullable String getUserId()
    • getReceivedUserId

      public @Nullable String getReceivedUserId()
      Return the user id from an incoming message.
      Returns:
      the user id.
      Since:
      1.6
    • setReceivedUserId

      public void setReceivedUserId(@Nullable String receivedUserId)
    • setAppId

      public void setAppId(@Nullable String appId)
    • getAppId

      public @Nullable String getAppId()
    • setClusterId

      public void setClusterId(@Nullable String clusterId)
    • getClusterId

      public @Nullable String getClusterId()
    • setType

      public void setType(@Nullable String type)
    • getType

      public @Nullable String getType()
    • setCorrelationId

      public void setCorrelationId(@Nullable String correlationId)
      Set the correlation id.
      Parameters:
      correlationId - the id.
    • getCorrelationId

      public @Nullable String getCorrelationId()
      Get the correlation id.
      Returns:
      the id.
    • setReplyTo

      public void setReplyTo(@Nullable String replyTo)
    • getReplyTo

      public @Nullable String getReplyTo()
    • setReplyToAddress

      public void setReplyToAddress(@Nullable Address replyTo)
    • getReplyToAddress

      public @Nullable Address getReplyToAddress()
    • setContentType

      public void setContentType(String contentType)
    • getContentType

      public String getContentType()
    • setContentEncoding

      public void setContentEncoding(@Nullable String contentEncoding)
    • getContentEncoding

      public @Nullable String getContentEncoding()
    • setContentLength

      public void setContentLength(long contentLength)
    • getContentLength

      public long getContentLength()
    • isContentLengthSet

      protected final boolean isContentLengthSet()
    • setDeliveryMode

      public void setDeliveryMode(@Nullable MessageDeliveryMode deliveryMode)
    • getDeliveryMode

      public @Nullable MessageDeliveryMode getDeliveryMode()
    • getReceivedDeliveryMode

      public @Nullable MessageDeliveryMode getReceivedDeliveryMode()
    • setReceivedDeliveryMode

      public void setReceivedDeliveryMode(@Nullable MessageDeliveryMode receivedDeliveryMode)
    • setExpiration

      public void setExpiration(@Nullable String expiration)
      Set the message expiration. This is a String property per the AMQP 0.9.1 spec. For RabbitMQ, this is a String representation of the message time to live in milliseconds.
      Parameters:
      expiration - the expiration.
    • getExpiration

      public @Nullable String getExpiration()
      Get the message expiration. This is a String property per the AMQP 0.9.1 spec. For RabbitMQ, this is a String representation of the message time to live in milliseconds.
      Returns:
      the expiration.
    • setPriority

      public void setPriority(Integer priority)
    • getPriority

      public Integer getPriority()
    • setReceivedExchange

      public void setReceivedExchange(@Nullable String receivedExchange)
    • getReceivedExchange

      public @Nullable String getReceivedExchange()
    • setReceivedRoutingKey

      public void setReceivedRoutingKey(@Nullable String receivedRoutingKey)
    • getReceivedRoutingKey

      public @Nullable String getReceivedRoutingKey()
    • getReceivedDelayLong

      @Deprecated(since="4.2", forRemoval=true) public @Nullable Long getReceivedDelayLong()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Since 4.2, for removal with the delayed-message-exchange plugin support.
      When a delayed message exchange is used the x-delay header on a received message contains the delay.
      Returns:
      the received delay.
      Since:
      3.1.2
      See Also:
    • setReceivedDelayLong

      @Deprecated(since="4.2", forRemoval=true) public void setReceivedDelayLong(@Nullable Long receivedDelay)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Since 4.2, for removal with the delayed-message-exchange plugin support.
      When a delayed message exchange is used the x-delay header on a received message contains the delay.
      Parameters:
      receivedDelay - the received delay.
      Since:
      3.1.2
      See Also:
    • setRedelivered

      public void setRedelivered(@Nullable Boolean redelivered)
    • isRedelivered

      public @Nullable Boolean isRedelivered()
    • getRedelivered

      public @Nullable Boolean getRedelivered()
    • setDeliveryTag

      public void setDeliveryTag(long deliveryTag)
    • getDeliveryTag

      public long getDeliveryTag()
    • isDeliveryTagSet

      protected final boolean isDeliveryTagSet()
    • setMessageCount

      public void setMessageCount(@Nullable Integer messageCount)
      Set the message count.
      Parameters:
      messageCount - the count
      See Also:
    • getMessageCount

      public @Nullable Integer getMessageCount()
      Return the server's most recent estimate of the number of messages remaining on the queue. Only applies to messages retrieved via basicGet.
      Returns:
      the count.
    • getConsumerTag

      public @Nullable String getConsumerTag()
    • setConsumerTag

      public void setConsumerTag(@Nullable String consumerTag)
    • getConsumerQueue

      public @Nullable String getConsumerQueue()
    • setConsumerQueue

      public void setConsumerQueue(@Nullable String consumerQueue)
    • getDeliveryTime

      public @Nullable Instant getDeliveryTime()
      Return the native RabbitMQ delivery time as an Instant.
      Returns:
      the delivery time, or null if it is not set or is not encoded as a Long.
      Since:
      4.2
      See Also:
    • getDeliveryTimeEpochMillis

      public @Nullable Long getDeliveryTimeEpochMillis()
      Return the native RabbitMQ delivery time as Unix epoch milliseconds.
      Returns:
      the delivery time, or null if it is not set or is not encoded as a Long.
      Since:
      4.2
    • setDeliveryTime

      public void setDeliveryTime(@Nullable Instant deliveryTime)
      Set the native RabbitMQ delivery time. The value is encoded as a Long containing Unix epoch milliseconds. RabbitMQ 4.4 applies this header to quorum queues; it is not a relative delay.
      Parameters:
      deliveryTime - the absolute delivery time, or null to remove the header.
      Since:
      4.2
      See Also:
    • setDeliveryTime

      public void setDeliveryTime(long epochMillis)
      Set the native RabbitMQ delivery time as Unix epoch milliseconds.
      Parameters:
      epochMillis - the absolute delivery time.
      Since:
      4.2
      See Also:
    • getDelayLong

      @Deprecated(since="4.2", forRemoval=true) public @Nullable Long getDelayLong()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Since 4.2, for removal with the delayed-message-exchange plugin support. RabbitMQ 4.4 quorum queues use getDeliveryTime() instead.
      Get the x-delay header long value used by the delayed-message-exchange plugin.
      Returns:
      the relative delay.
      Since:
      3.1.2
    • setDelayLong

      @Deprecated(since="4.2", forRemoval=true) public void setDelayLong(@Nullable Long delay)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Since 4.2, for removal with the delayed-message-exchange plugin support. RabbitMQ 4.4 quorum queues use setDeliveryTime(Instant) instead.
      Set the x-delay header to a long value for the delayed-message-exchange plugin.
      Parameters:
      delay - the relative delay.
      Since:
      3.1.2
    • getRetryCount

      public long getRetryCount()
      The number of retries for this message over broker.
      Returns:
      the retry count
      Since:
      3.2
    • setRetryCount

      public void setRetryCount(long retryCount)
      Set a number of retries for this message over broker.
      Parameters:
      retryCount - the retry count.
      Since:
      3.2
      See Also:
    • incrementRetryCount

      public void incrementRetryCount()
      Increment a retry count for this message when it is re-published back to the broker.
      Since:
      3.2
    • isFinalRetryForMessageWithNoId

      public boolean isFinalRetryForMessageWithNoId()
    • setFinalRetryForMessageWithNoId

      public void setFinalRetryForMessageWithNoId(boolean finalRetryForMessageWithNoId)
    • getPublishSequenceNumber

      public long getPublishSequenceNumber()
      Return the publishing sequence number if publisher confirms are enabled; set by the template.
      Returns:
      the sequence number.
      Since:
      2.1
    • setPublishSequenceNumber

      public void setPublishSequenceNumber(long publishSequenceNumber)
      Set the publishing sequence number, if publisher confirms are enabled; set by the template.
      Parameters:
      publishSequenceNumber - the sequence number.
      Since:
      2.1
    • getInferredArgumentType

      public @Nullable Type getInferredArgumentType()
      The inferred target argument type when using a method-level @RabbitListener.
      Returns:
      the type.
      Since:
      1.6
    • setInferredArgumentType

      public void setInferredArgumentType(@Nullable Type inferredArgumentType)
      Set the inferred target argument type when using a method-level @RabbitListener.
      Parameters:
      inferredArgumentType - the type.
      Since:
      1.6
    • getTargetMethod

      public @Nullable Method getTargetMethod()
      The target method when using a @RabbitListener.
      Returns:
      the method.
      Since:
      1.6
    • setTargetMethod

      public void setTargetMethod(@Nullable Method targetMethod)
      Set the target method when using a @RabbitListener.
      Parameters:
      targetMethod - the target method.
      Since:
      1.6
    • getTargetBean

      public @Nullable Object getTargetBean()
      The target bean when using @RabbitListener.
      Returns:
      the bean.
      Since:
      1.6
    • setTargetBean

      public void setTargetBean(@Nullable Object targetBean)
      Set the target bean when using @RabbitListener.
      Parameters:
      targetBean - the bean.
      Since:
      1.6
    • isLastInBatch

      public boolean isLastInBatch()
      When true; the message having these properties is the last message from a batch.
      Returns:
      true for the last message.
      Since:
      2.2
    • setLastInBatch

      public void setLastInBatch(boolean lastInBatch)
      Set to true to indicate these properties are for the last message in a batch.
      Parameters:
      lastInBatch - true for the last.
      Since:
      2.2
    • isProjectionUsed

      public boolean isProjectionUsed()
      Get an internal flag used to communicate that conversion used projection; always false at the application level.
      Returns:
      true if projection was used.
      Since:
      2.2.20
    • setProjectionUsed

      public void setProjectionUsed(boolean projectionUsed)
      Set an internal flag used to communicate that conversion used projection; always false at the application level.
      Parameters:
      projectionUsed - true for projection.
      Since:
      2.2.20
    • getXDeathHeader

      public @Nullable List<Map<String,?>> getXDeathHeader()
      Return the x-death header. If header value is not a List or its elements are not a Map, ignore and return null.
      Returns:
      the header.
    • getAmqpAcknowledgment

      public @Nullable AmqpAcknowledgment getAmqpAcknowledgment()
      Return the AmqpAcknowledgment for consumer if any.
      Returns:
      the AmqpAcknowledgment for consumer if any.
      Since:
      4.0
    • setAmqpAcknowledgment

      public void setAmqpAcknowledgment(@Nullable AmqpAcknowledgment amqpAcknowledgment)
      Set an AmqpAcknowledgment for manual acks in the target message processor. This is only in-application a consumer side logic.
      Parameters:
      amqpAcknowledgment - the AmqpAcknowledgment to use in the application.
      Since:
      4.0
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object