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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.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 在wordcount应用程序的上下文中,Kafka KTable中的单词计数以某个随机值开始_Apache Kafka_Apache Kafka Streams_Spring Cloud Stream - Fatal编程技术网

Apache kafka 在wordcount应用程序的上下文中,Kafka KTable中的单词计数以某个随机值开始

Apache kafka 在wordcount应用程序的上下文中,Kafka KTable中的单词计数以某个随机值开始,apache-kafka,apache-kafka-streams,spring-cloud-stream,Apache Kafka,Apache Kafka Streams,Spring Cloud Stream,在Kafka Streams Wordcount应用程序中,我按键对传入记录进行分组,并将计数存储在具体化的KTable中: public void process(@Input(Binding.INPUT) KStream<String, String> stream) { stream .peek((k, v) -> { System.out.println("INCOMING :: KEY = " + k +

在Kafka Streams Wordcount应用程序中,我按键对传入记录进行分组,并将计数存储在具体化的KTable中:

public void process(@Input(Binding.INPUT) KStream<String, String> stream) {
   stream
            .peek((k, v) -> {
                System.out.println("INCOMING :: KEY = " + k + " , VALUE = " + v);
            })
            .map((k, v) -> new KeyValue<>(v, v))
            .groupByKey()
            .count(Materialized.as(Binding.STORENAME));
}
public void进程(@Input(Binding.Input)KStream-stream){
流动
.peek((k,v)->{
System.out.println(“传入::KEY=“+k+”,VALUE=“+v”);
})
.map((k,v)->新键值(v,v))
.groupByKey()
.count(具体化的.as(Binding.STORENAME));
}
我正在使用InteractiveQueryService从卡夫卡商店阅读:

@Component
public class CountQueryProcessor {

    @Autowired
    private InteractiveQueryService interactiveQueryService;

    private ReadOnlyKeyValueStore<String, Long> readOnlyKeyValueStore;

    @Scheduled(initialDelay = 0, fixedDelay = 5000)
    public void queryStore() {
        readOnlyKeyValueStore = interactiveQueryService.getQueryableStore(Binding.STORENAME, QueryableStoreTypes.keyValueStore());

        KeyValueIterator<String, Long> iterator = readOnlyKeyValueStore.all();
        while(iterator.hasNext())   {
            KeyValue<String, Long> next = iterator.next();
            System.out.println("Query :: Word = " + next.key + " , Count = " + next.value);
        }
    }
}
@组件
公共类CountQueryProcessor{
@自动连线
私有InteractiveQueryService InteractiveQueryService;
私有ReadOnlyKeyValueStore ReadOnlyKeyValueStore;
@计划(初始延迟=0,固定延迟=5000)
公共无效queryStore(){
readOnlyKeyValueStore=interactiveQueryService.getQueryableStore(Binding.STORENAME,QueryableStoreTypes.keyValueStore());
KeyValueIterator迭代器=readOnlyKeyValueStore.all();
while(iterator.hasNext()){
KeyValue next=iterator.next();
System.out.println(“Query::Word=“+next.key+”,Count=“+next.value”);
}
}
}
打印KTable存储区中的值时,其值从随机值开始并开始递增。 我不明白为什么会这样


任何解决方案和幕后解释都会很有帮助。

你能将观察到的结果添加到问题中吗,即“随机值”是什么意思?你是说计数不是从1开始的吗?是的@Matthias,计数不是从1开始的,是吗,也就是说,找到旧的地方州?尝试更改
应用程序.id
以验证这是否可以解决问题?