Class KafkaMessageHeaderAccessor

java.lang.Object
org.springframework.messaging.support.MessageHeaderAccessor
org.springframework.kafka.support.KafkaMessageHeaderAccessor

public class KafkaMessageHeaderAccessor extends MessageHeaderAccessor
A header accessor to provide convenient access to certain headers in a type specific manner.
Since:
3.0.10
Author:
Gary Russell
  • Constructor Details

    • KafkaMessageHeaderAccessor

      public KafkaMessageHeaderAccessor(Message<?> message)
      Construct an instance for the provided message.
      Parameters:
      message - the message.
  • Method Details

    • getBlockingRetryDeliveryAttempt

      public int getBlockingRetryDeliveryAttempt()
      Access the header value when the blocking delivery attempt header is present.
      Returns:
      1 if there is no header present; the decoded header value otherwise.
      Throws:
      IllegalStateException - if the header is not present.
      See Also:
    • getNonBlockingRetryDeliveryAttempt

      public int getNonBlockingRetryDeliveryAttempt()
      When using non-blocking retries, get the delivery attempt header value as an int.
      Returns:
      1 if there is no header present; the decoded header value otherwise.
    • getHeader

      @Nullable public <T> T getHeader(String key, Class<T> type)
      Get a header value with a specific type.
      Type Parameters:
      T - the type.
      Parameters:
      key - the header name.
      type - the type's Class.
      Returns:
      the value, if present.
      Throws:
      IllegalArgumentException - if the type is not correct.
    • createAccessor

      protected MessageHeaderAccessor createAccessor(Message<?> message)
      Overrides:
      createAccessor in class MessageHeaderAccessor
    • wrap

      public static KafkaMessageHeaderAccessor wrap(Message<?> message)
      Create an instance from the payload and headers of the given Message.
      Parameters:
      message - the message.
      Returns:
      the accessor.