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. SeeAbstractKafkaHeaderMapper.setRawMappedHeaders(Map)
. Most headers inKafkaHeaders
are not mapped on outbound messages. The exceptions are correlation and reply headers for request/reply- Since:
- 2.1.3
- Author:
- Gary Russell
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.springframework.kafka.support.AbstractKafkaHeaderMapper
AbstractKafkaHeaderMapper.HeaderMatcher, AbstractKafkaHeaderMapper.NeverMatchHeaderMatcher, AbstractKafkaHeaderMapper.SimplePatternBasedHeaderMatcher
-
-
Field Summary
-
Fields inherited from class org.springframework.kafka.support.AbstractKafkaHeaderMapper
logger
-
-
Constructor Summary
Constructors Constructor Description SimpleKafkaHeaderMapper()
Construct an instance with the default object mapper and default header patterns for outbound headers; all inbound headers are mapped.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.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SimpleKafkaHeaderMapper
forInboundOnlyWithMatchers(java.lang.String... patterns)
Create an instance for inbound mapping only with pattern matching.void
fromHeaders(org.springframework.messaging.MessageHeaders headers, org.apache.kafka.common.header.Headers target)
Map from the givenMessageHeaders
to the specified target headers.void
toHeaders(org.apache.kafka.common.header.Headers source, java.util.Map<java.lang.String,java.lang.Object> target)
Map from the given target headers to abstractedMessageHeaders
.-
Methods inherited from class org.springframework.kafka.support.AbstractKafkaHeaderMapper
addMatchers, addRawMappedHeader, getCharset, headerValueToAddIn, headerValueToAddOut, matches, matches, matchesForInbound, setCharset, setMapAllStringsOut, setRawMappedHeaders
-
-
-
-
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 inKafkaHeaders
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 inKafkaHeaders
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 givenMessageHeaders
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 abstractedMessageHeaders
.- Parameters:
source
- the native target headers.target
- the target headers.
-
-