【问题标题】:Kafka - Adding custom headers to record metadataKafka - 添加自定义标头以记录元数据
【发布时间】:2020-02-25 06:05:54
【问题描述】:

kafka 是否允许添加自定义标头来记录元数据。代码表明它没有。有人试过吗?

【问题讨论】:

标签: apache-kafka


【解决方案1】:

从 0.11.0.0 版本到 KIP-82 - Add Record Headers 包括对自定义标头的支持。

例如,你可以使用这个method

public ProducerRecord(String topic,
                      Integer partition,
                      K key,
                      V value,
                      Iterable<Header> headers)

另请参阅相关问题:

  1. Adding Custom Headers in Kafka Message
  2. Header information in kafka producer API

【讨论】:

    【解决方案2】:

    是的,the Java API 有标题

    public ProducerRecord(java.lang.String topic,
                              java.lang.Integer partition,
                              java.lang.Long timestamp,
                              K key,
                              V value,
                              java.lang.Iterable headers)

    创建具有指定时间戳的记录,发送到指定主题和分区

    Parameters:
        topic - The topic the record will be appended to
        partition - The partition to which the record should be sent
        timestamp - The timestamp of the record, in milliseconds since epoch. If null, the producer will assign the timestamp using System.currentTimeMillis().
        key - The key that will be included in the record
        value - The record contents
        headers - the headers that will be included in the record

    【讨论】:

      猜你喜欢
      • 2018-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-05
      • 2012-05-17
      • 1970-01-01
      • 2012-04-23
      • 1970-01-01
      相关资源
      最近更新 更多