简体   繁体   English

Kafka Streams 应用程序生成具有相同消息的主题

[英]Kafka Streams application producing topic with same message

I am facing an issue with my Kafka streams application, where messages are being processed multiple times and the result topic is constantly receiving messages.我的 Kafka 流应用程序遇到了一个问题,其中消息被多次处理并且结果主题不断接收消息。 This issue is only present in production and not in my local environment.此问题仅存在于生产环境中,不存在于我的本地环境中。 Can you help me determine the root cause of this problem, based on the transformer code?你能根据转换器代码帮我确定这个问题的根本原因吗?

@Override
public KeyValue<String, UserClicks> transform(final String user, final Long clicks) {

                UserClicks userClicks = tempStore.get(user);

                if (userClicks != null) {
                    userClicks.clicks += clicks;
                }
                else {
                    final String region = regionStore.get(user).value(); 
                    userClicks = new UserClicks(user, region, clicks);
                }

                if (userClicks.clicks < CLICKS_THRESHOLD) {
                    tempStore.put(user, userClicks);
                }
                else {
                    tempStore.delete(user);
                }

                return KeyValue.pair(user, userClicks);
            }

` `

When I remove KStore from transformer everything seems to work fine.当我从变压器中删除 KStore 时,一切似乎都正常。

Usally this problem occures becuase kafka can't save its state, and it's reading the same batch of messages.通常发生此问题是因为 kafka 无法保存其 state,并且它正在读取同一批消息。 KStore stores it's state on change log topic, and it stores it by producing messages. KStore 将其 state 存储在更改日志主题上,并通过生成消息来存储它。 If the produces can't produce for some reson, new offset can never be commited.如果产品因某种共鸣而无法生产,则永远无法提交新的偏移量。

To resolve the issue, change the minimum number of in-sync replicas to 1 or set the replication factor to 2. By default, Kafka streams creates a replication factor of 1. Easy way to configure this is through Conduktor, just go to topic config and changes min.insync.replicas property要解决此问题,请将同步副本的最小数量更改为 1 或将复制因子设置为 2。默认情况下,Kafka 流创建的复制因子为 1。配置它的简单方法是通过 Conduktor,只需 go 到主题配置并更改 min.insync.replicas 属性在此处输入图像描述 It cant also be done through kafka CLI by running this command.它也不能通过运行此命令通过 kafka CLI 完成。

kafka-configs.sh --bootstrap-server localhost:9092 --alter --entity-type topics --entity-name configured-topic min.insync.replicas 1

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

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