Kafka Connect SMT to add Kafka header fields

一曲冷凌霜 提交于 2021-01-29 13:59:01

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!