Class SimpleKafkaHeaderMapper
java.lang.Object
org.springframework.kafka.support.AbstractKafkaHeaderMapper
org.springframework.kafka.support.SimpleKafkaHeaderMapper
- All Implemented Interfaces:
KafkaHeaderMapper
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
-
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
ConstructorDescriptionConstruct an instance with the default object mapper and default header patterns for outbound headers; all inbound headers are mapped.SimpleKafkaHeaderMapper
(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
Modifier and TypeMethodDescriptionstatic SimpleKafkaHeaderMapper
forInboundOnlyWithMatchers
(String... patterns) Create an instance for inbound mapping only with pattern matching.void
fromHeaders
(MessageHeaders headers, org.apache.kafka.common.header.Headers target) Map from the givenMessageHeaders
to the specified target headers.void
Map from the given native headers to a map of headers for the eventualMessageHeaders
.Methods inherited from class org.springframework.kafka.support.AbstractKafkaHeaderMapper
addMatchers, addRawMappedHeader, getCharset, headerValueToAddIn, headerValueToAddOut, matches, matches, matchesForInbound, setCharset, setMapAllStringsOut, setRawMappedHeaders
-
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 inKafkaHeaders
are never mapped as headers since they represent data in consumer/producer records. -
SimpleKafkaHeaderMapper
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:
-
-
Method Details
-
forInboundOnlyWithMatchers
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
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
Description copied from interface:KafkaHeaderMapper
Map from the given native headers to a map of headers for the eventualMessageHeaders
.- Parameters:
source
- the native headers.target
- the target headers.
-