简体   繁体   English

从Kafka中间主题中删除消息

[英]Removing message from Kafka intermediate topic

I have a topic named SOURCE which contains a stream of two kinds of messages, A and B. I have written a kafka-streams application that consumes that topic, finds an A and a B with the same correlation ID and aggregates them into a new message C and puts that on the output topic DESTINATION 我有一个名为SOURCE的主题,其中包含两种消息流,即A和B。我编写了一个使用该主题的kafka-streams应用程序,找到了具有相同相关ID的A和B,并将它们聚合成一个新的消息C并将其放在输出主题DESTINATION上

Sometimes an A without a B (or wise versa) will put on the SOURCE topic. 有时A而不B(或者反之亦然)会放在SOURCE主题上。 I have created a queryable state store so I can look at these dangling messages but now I'd like to delete a specific message from the intermediate topic. 我创建了一个可查询的状态存储,因此我可以查看这些悬空的消息,但是现在我想从中间主题中删除特定的消息。 I guessing it's just a matter of getting a message with the right key (which I have) and null ass the body into the intermediate topic. 我猜这只是用正确的键(我拥有)获取消息并将主体的null插入中间主题的问题。 The question is what is the best way? 问题是最好的方法是什么?

  1. Produce a special clear-message to SOURCE which would cause the aggregated message to become null 对SOURCE产生特殊的清除消息,这将导致聚合消息变为空
  2. Write a message directly to the intermediate topic with null data 使用空数据直接将消息写到中间主题
  3. some other way, maybe kafka-streams already have an API call for this? 其他方式,也许kafka-streams已经为此提供了API调用?

Bonus question: If I know that I don't want messages to sit in the intermediate topic for longer than 6months, can I instruct kafka-streams to create the intermediate topic with 6m retention or should I create the topic myself manually before I run the app? 额外的问题:如果我不希望消息在中间主题中停留超过6个月,我可以指示kafka-streams创建保留6m的中间主题,还是应该在运行主题之前自行创建主题应用程式?

Bonus question: If I know that I don't want messages to sit in the intermediate topic for longer than 6months, can I instruct kafka-streams to create the intermediate topic with 6m retention or should I create the topic myself manually before I run the app? 额外的问题:如果我不希望消息在中间主题中停留超过6个月,我可以指示kafka-streams创建保留6m的中间主题,还是应该在运行主题之前自行创建主题应用程式?

Yes you can set retention time for example: 是的,您可以设置保留时间,例如:

kafka/bin/kafka-configs.sh --zookeeper localhost:2181 --entity-type topics --entity-name my_topic --alter --add-config retention.ms=16070400000

Or while creating the topic: 或在创建主题时:

kafka/bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 2 --partitions 10 --if-not-exists --config retention.ms=16070400000 --topic my_topic

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

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