Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache kafka 卡夫卡保留政策没有';I don’我没有按预期工作_Apache Kafka_Purge - Fatal编程技术网

Apache kafka 卡夫卡保留政策没有';I don’我没有按预期工作

Apache kafka 卡夫卡保留政策没有';I don’我没有按预期工作,apache-kafka,purge,Apache Kafka,Purge,我想为我们有的一些用例实现一个数据重播,为此,我需要使用Kafka保留策略(我使用的是join,我需要准确的窗口时间)。 另外,我正在使用卡夫卡版本0.10.1.1 我将数据发送到主题中,如下所示: kafkaProducer.send( new ProducerRecord<>(kafkaTopic, 0, (long) r.get("date_time") ,r.get(keyFieldName).toString(), r)

我想为我们有的一些用例实现一个数据重播,为此,我需要使用Kafka保留策略(我使用的是join,我需要准确的窗口时间)。 另外,我正在使用卡夫卡版本0.10.1.1

我将数据发送到主题中,如下所示:

 kafkaProducer.send(
                    new ProducerRecord<>(kafkaTopic, 0, (long) r.get("date_time") ,r.get(keyFieldName).toString(), r)
            );
############################# Log Retention Policy #############################

# The following configurations control the disposal of log segments. The policy can
# be set to delete segments after a period of time, or after a given size has accumulated.
# A segment will be deleted whenever *either* of these criteria are met. Deletion always happens
# from the end of the log.

# The minimum age of a log file to be eligible for deletion
log.retention.hours=168

# A size-based retention policy for logs. Segments are pruned from the log as long as the remaining
# segments don't drop below log.retention.bytes.
#log.retention.bytes=1073741824

# The maximum size of a log segment file. When this size is reached a new log segment will be created.
log.segment.bytes=1073741824

# The interval at which log segments are checked to see if they can be deleted according
# to the retention policies
log.retention.check.interval.ms=300000
为了进行测试,我向我的主题发送了4条消息,我得到了这4条日志消息

2017-02-28 10:23:39信息 ConsumerRecordOrWallclockTimestampExtractor:21-时间戳: 1488295086292人类可读-美国东部时间2017年2月28日星期二10:18:06
2017-02-28 10:24:01信息消费者记录或墙时钟时间抽取器:21- 时间戳:1483272000000人类可读-太阳2017年1月1日07:00:00东部标准时间
2017-02-28 10:26:11信息 ConsumerRecordOrWallclockTimestampExtractor:21-时间戳: 1485820800000人可读-2017年1月30日星期一19:00:00东部标准时间
2017-02-28 10:27:22信息消费者记录或墙时钟时间提取程序:21- 时间戳:1488295604411人类可读-美国东部时间2017年2月28日星期二10:26:44

因此,根据我的预期,我的两条消息在5分钟后被清除/删除(第二条和第三条消息,因为它们是为1月1日和1月30日发送的)。但是我试着花了一个小时来阅读我的主题,每次我阅读完我的主题,我就收到了所有的4条信息

kafka avro控制台使用者--zookeeper本地主机:2181 --从一开始——主题myTopic

我的卡夫卡配置如下:

 kafkaProducer.send(
                    new ProducerRecord<>(kafkaTopic, 0, (long) r.get("date_time") ,r.get(keyFieldName).toString(), r)
            );
############################# Log Retention Policy #############################

# The following configurations control the disposal of log segments. The policy can
# be set to delete segments after a period of time, or after a given size has accumulated.
# A segment will be deleted whenever *either* of these criteria are met. Deletion always happens
# from the end of the log.

# The minimum age of a log file to be eligible for deletion
log.retention.hours=168

# A size-based retention policy for logs. Segments are pruned from the log as long as the remaining
# segments don't drop below log.retention.bytes.
#log.retention.bytes=1073741824

# The maximum size of a log segment file. When this size is reached a new log segment will be created.
log.segment.bytes=1073741824

# The interval at which log segments are checked to see if they can be deleted according
# to the retention policies
log.retention.check.interval.ms=300000

我是做错了什么还是错过了什么?

卡夫卡通过删除日志段来实施其保留策略。Kafka从不删除活动段,即它将在其中附加发送到分区的新消息的段。卡夫卡只删除旧片段。当向分区发送新消息时,Kafka将活动段滚动到旧段,并且

  • 带有新消息的活动段的大小将超过
    log.segment.bytes
    ,或
  • 活动段中第一条消息的时间戳早于
    log.roll.ms
    (默认为7天)

因此,在您的示例中,您必须在2017年2月28日星期二10:18:06 EST之后等待7天,发送一条新消息,然后所有4条初始消息都将被删除

如果是这样的话,它如何解释当我在5分钟后发送了两条带有1970年时间戳的消息(非常旧的消息),这两条消息都被删除了?