KAFKA-5142: Add Connect support for message headers (KIP-145)
**[KIP-145](https://cwiki.apache.org/confluence/display/KAFKA/KIP-145+-+Expose+Record+Headers+in+Kafka+Connect) has been accepted, and this PR implements KIP-145 except without the SMTs.** Changed the Connect API and runtime to support message headers as described in [KIP-145](https://cwiki.apache.org/confluence/display/KAFKA/KIP-145+-+Expose+Record+Headers+in+Kafka+Connect). The new `Header` interface defines an immutable representation of a Kafka header (key-value pair) with support for the Connect value types and schemas. This interface provides methods for easily converting between many of the built-in primitive, structured, and logical data types. The new `Headers` interface defines an ordered collection of headers and is used to track all headers associated with a `ConnectRecord` (and thus `SourceRecord` and `SinkRecord`). This does allow multiple headers with the same key. The `Headers` contains methods for adding, removing, finding, and modifying headers. Convenience methods allow connectors and transforms to easily use and modify the headers for a record. A new `HeaderConverter` interface is also defined to enable the Connect runtime framework to be able to serialize and deserialize headers between the in-memory representation and Kafka’s byte[] representation. A new `SimpleHeaderConverter` implementation has been added, and this serializes to strings and deserializes by inferring the schemas (`Struct` header values are serialized without the schemas, so they can only be deserialized as `Map` instances without a schema.) The `StringConverter`, `JsonConverter`, and `ByteArrayConverter` have all been extended to also be `HeaderConverter` implementations. Each connector can be configured with a different header converter, although by default the `SimpleHeaderConverter` is used to serialize header values as strings without schemas. Unit and integration tests are added for `ConnectHeader` and `ConnectHeaders`, the two implementation classes for headers. Additional test methods are added for the methods added to the `Converter` implementations. Finally, the `ConnectRecord` object is already used heavily, so only limited tests need to be added while quite a few of the existing tests already cover the changes. Author: Randall Hauch <rhauch@gmail.com> Reviewers: Arjun Satish <arjun@confluent.io>, Ted Yu <yuzhihong@gmail.com>, Magesh Nandakumar <magesh.n.kumar@gmail.com>, Konstantine Karantasis <konstantine@confluent.io>, Ewen Cheslack-Postava <ewen@confluent.io> Closes #4319 from rhauch/kafka-5142-b
Showing
- checkstyle/import-control.xml 1 addition, 0 deletionscheckstyle/import-control.xml
- checkstyle/suppressions.xml 9 additions, 1 deletioncheckstyle/suppressions.xml
- connect/api/src/main/java/org/apache/kafka/connect/connector/ConnectRecord.java 60 additions, 1 deletion...ava/org/apache/kafka/connect/connector/ConnectRecord.java
- connect/api/src/main/java/org/apache/kafka/connect/data/Values.java 1117 additions, 0 deletions...i/src/main/java/org/apache/kafka/connect/data/Values.java
- connect/api/src/main/java/org/apache/kafka/connect/header/ConnectHeader.java 97 additions, 0 deletions...n/java/org/apache/kafka/connect/header/ConnectHeader.java
- connect/api/src/main/java/org/apache/kafka/connect/header/ConnectHeaders.java 519 additions, 0 deletions.../java/org/apache/kafka/connect/header/ConnectHeaders.java
- connect/api/src/main/java/org/apache/kafka/connect/header/Header.java 66 additions, 0 deletions...src/main/java/org/apache/kafka/connect/header/Header.java
- connect/api/src/main/java/org/apache/kafka/connect/header/Headers.java 308 additions, 0 deletions...rc/main/java/org/apache/kafka/connect/header/Headers.java
- connect/api/src/main/java/org/apache/kafka/connect/sink/SinkRecord.java 14 additions, 2 deletions...c/main/java/org/apache/kafka/connect/sink/SinkRecord.java
- connect/api/src/main/java/org/apache/kafka/connect/source/SourceRecord.java 17 additions, 2 deletions...in/java/org/apache/kafka/connect/source/SourceRecord.java
- connect/api/src/main/java/org/apache/kafka/connect/storage/ConverterConfig.java 58 additions, 0 deletions...ava/org/apache/kafka/connect/storage/ConverterConfig.java
- connect/api/src/main/java/org/apache/kafka/connect/storage/ConverterType.java 64 additions, 0 deletions.../java/org/apache/kafka/connect/storage/ConverterType.java
- connect/api/src/main/java/org/apache/kafka/connect/storage/HeaderConverter.java 53 additions, 0 deletions...ava/org/apache/kafka/connect/storage/HeaderConverter.java
- connect/api/src/main/java/org/apache/kafka/connect/storage/SimpleHeaderConverter.java 85 additions, 0 deletions...g/apache/kafka/connect/storage/SimpleHeaderConverter.java
- connect/api/src/main/java/org/apache/kafka/connect/storage/StringConverter.java 44 additions, 15 deletions...ava/org/apache/kafka/connect/storage/StringConverter.java
- connect/api/src/main/java/org/apache/kafka/connect/storage/StringConverterConfig.java 60 additions, 0 deletions...g/apache/kafka/connect/storage/StringConverterConfig.java
- connect/api/src/test/java/org/apache/kafka/connect/data/ValuesTest.java 350 additions, 0 deletions...c/test/java/org/apache/kafka/connect/data/ValuesTest.java
- connect/api/src/test/java/org/apache/kafka/connect/header/ConnectHeaderTest.java 108 additions, 0 deletions...va/org/apache/kafka/connect/header/ConnectHeaderTest.java
- connect/api/src/test/java/org/apache/kafka/connect/header/ConnectHeadersTest.java 547 additions, 0 deletions...a/org/apache/kafka/connect/header/ConnectHeadersTest.java
- connect/api/src/test/java/org/apache/kafka/connect/sink/SinkRecordTest.java 128 additions, 0 deletions...st/java/org/apache/kafka/connect/sink/SinkRecordTest.java
This diff is collapsed.
This diff is collapsed.
Please register or sign in to comment