Class 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 Detail

      • 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​(java.lang.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:
        PatternMatchUtils.simpleMatch(String, String)
    • Method Detail

      • forInboundOnlyWithMatchers

        public static SimpleKafkaHeaderMapper forInboundOnlyWithMatchers​(java.lang.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​(org.springframework.messaging.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,
                              java.util.Map<java.lang.String,​java.lang.Object> target)
        Description copied from interface: KafkaHeaderMapper
        Map from the given target headers to abstracted MessageHeaders.
        Parameters:
        source - the native target headers.
        target - the target headers.