Class SimpleKafkaHeaderMapper

java.lang.Object
org.springframework.kafka.support.AbstractKafkaHeaderMapper
org.springframework.kafka.support.SimpleKafkaHeaderMapper
All Implemented Interfaces:
KafkaHeaderMapper

public class SimpleKafkaHeaderMapper extends AbstractKafkaHeaderMapper
A simple header mapper that maps headers directly; for outbound, only byte[] headers are mapped; for inbound, headers are mapped unchanged, as byte[]. Strings can also be mapped to/from byte. See AbstractKafkaHeaderMapper.setRawMappedHeaders(Map). Most headers in KafkaHeaders are not mapped on outbound messages. The exceptions are correlation and reply headers for request/reply
Since:
2.1.3
Author:
Gary Russell
  • Constructor Details

    • SimpleKafkaHeaderMapper

      public SimpleKafkaHeaderMapper()
      Construct an instance with the default object mapper and default header patterns for outbound headers; all inbound headers are mapped. The default pattern list is "!id", "!timestamp" and "*". In addition, most of the headers in KafkaHeaders are never mapped as headers since they represent data in consumer/producer records.
    • SimpleKafkaHeaderMapper

      public SimpleKafkaHeaderMapper(String... patterns)
      Construct an instance with a default object mapper and the provided header patterns for outbound headers; all inbound headers are mapped. The patterns are applied in order, stopping on the first match (positive or negative). Patterns are negated by preceding them with "!". The patterns will replace the default patterns; you generally should not map the "id" and "timestamp" headers. Note: most of the headers in KafkaHeaders are never mapped as headers since they represent data in consumer/producer records.
      Parameters:
      patterns - the patterns.
      See Also:
  • Method Details

    • forInboundOnlyWithMatchers

      public static SimpleKafkaHeaderMapper forInboundOnlyWithMatchers(String... patterns)
      Create an instance for inbound mapping only with pattern matching.
      Parameters:
      patterns - the patterns to match.
      Returns:
      the header mapper.
      Since:
      2.8.8
    • fromHeaders

      public void fromHeaders(MessageHeaders headers, org.apache.kafka.common.header.Headers target)
      Description copied from interface: KafkaHeaderMapper
      Map from the given MessageHeaders to the specified target headers.
      Parameters:
      headers - the abstracted MessageHeaders.
      target - the native target headers.
    • toHeaders

      public void toHeaders(org.apache.kafka.common.header.Headers source, Map<String,Object> target)
      Description copied from interface: KafkaHeaderMapper
      Map from the given native headers to a map of headers for the eventual MessageHeaders.
      Parameters:
      source - the native headers.
      target - the target headers.