简体   繁体   English

不要坚持主题卡夫卡

[英]Dont persist topic Kafka

I have a use case for Kafka where I dont need the logs of some topics that are running on the server, some topics send a lot of messages while other not so much. 我有一个用于Kafka的用例,其中我不需要服务器上正在运行的某些主题的日志,某些主题发送了很多消息,而其他则不需要太多。

Currently the only "fix" I see was to set a pretty lax retention policy. 目前,我看到的唯一“修复”是设置一个宽松的保留策略。

Thing is that I would like to keep the logs and persistent information for some other topics that are on the server, which are arguably more important to me. 问题是我想保留服务器上其他一些主题的日志和持久性信息,这对我来说可能更重要。

What options do I have ? 我有什么选择?

Ideally I would like to discard logs and stored messages by topic. 理想情况下,我想按主题丢弃日志和存储的消息。

You can set per-topic retention policies, yes. 您可以设置每个主题的保留策略,可以。

Here's an example using kafka-topics : 这是使用kafka-topics的示例:

kafka-topics.sh --zookeeper localhost:2181 \
                --alter \
                --topic MyTopic \
                --config retention.ms=1000

The retention settings can be set on a per-topic basis. 保留设置可以按主题设置。 You can do that either at creation time or alter the topic config once created. 您可以在创建时执行此操作,也可以在创建后更改主题配置。 You can find the full list of topic configs on Kafka's website . 您可以在Kafka的网站上找到主题配置的完整列表。

For topics you don't need to keep data, set retention limits that will delete data frequently. 对于不需要保留数据的主题,请设置保留限制,该限制将频繁删除数据。

On the other hand, for topics you need to keep the data, set retention limits that will keep the data for longer period of time. 另一方面,对于您需要保留数据的主题,请设置保留限制,以将数据保留更长的时间。

For example, to set topic config when creating a topic (retention time=24hours): 例如,要在创建主题时设置主题配置(保留时间= 24小时):

kafka-topics.sh --zookeeper <ZK> --create --topic --partitions 1 --replication-factor 1 --config retention.ms=86400000

To update an existing topic: 更新现有主题:

kafka-configs.sh --zookeeper <ZK> --entity-type topics --entity-name <TOPIC> --alter --add-config retention.ms=86400000

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM