问题
I need to find or write an SMT that will add header fields to a request. The request is missing some type fields and I want to add them.
How exactly do you add a header within an SMT all I have seen are just record transforms like below but what if its the header I want to change or add a field to?
private R applySchemaless(R record) {
final Map<String, Object> value = requireMap(operatingValue(record), PURPOSE);
// record.headers.add(Header) but how do I define the header
// or record.headers.add(String, Schema) but I am not sure how to define Schema?
final Map<String, Object> updatedValue = new HashMap<>(value);
updatedValue.put(fieldName, getRandomUuid());
return newRecord(record, null, updatedValue);
}
回答1:
This should work
Headers headers = new ConnectHeaders();
headers.add(myKey, myValue, mySchema);
headers.forEach(h -> record.headers().add(h));
ConnectHeaders info can be found here - https://kafka.apache.org/25/javadoc/org/apache/kafka/connect/header/Headers.html
来源:https://stackoverflow.com/questions/63293037/kafka-connect-smt-to-add-kafka-header-fields