本文介绍了KTable无法从实例化视图获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Spring Boot中使用Kafka Streams.在我的用例中,当我收到客户事件时,我需要将其存储在customer-store实例化视图中,当我收到订单事件时,我需要加入客户并下订单,然后将结果存储在customer-order实例化视图中.

I am using Kafka Streams with Spring Boot. In my use case when I receive customer event I need to store it in customer-store materialized view and when I receive order event, I need to join customer and order then store the result in customer-order materialized view.

StoreBuilder customerStateStore = Stores.keyValueStoreBuilder(Stores.persistentKeyValueStore("customer-store"),Serdes.String(), customerSerde)
                .withLoggingEnabled(new HashMap<>());
streamsBuilder.stream("customer", Consumed.with(Serdes.String(), customerSerde)).to("customer-to-ktable-topic",Produced.with(Serdes.String(), customerSerde));
KTable<String, Customer> customerKTable = streamsBuilder.table("customer-to-ktable-topic", Consumed.with(Serdes.String(), customerSerde),Materialized.as(customerStateStore.name()));

这是问题所在,当我收到Order事件并且我的customerKTable返回null时,联接操作变得无用.这不是它应该如何工作的.我的代码类似于 Kafka音乐示例,我创建了TestConsumer类对此进行测试.代码已上传到 Github 供参考.

Here is the problem, when I receive Order event and my customerKTable returns null and join operation becomes useless. This is not how it supposed to work. My code is similar to Kafka Music example, I created TestConsumer class to test this. Code uploaded to Github for reference.

推荐答案

此问题是由KTable创建的.我使用的KTable语法在语法上是正确的,但无法正常工作.请参阅此问题以了解更多信息信息.更改KTable语法对我有用.现在,customerKTable在Order事件到达时从实例化视图返回事件或对象.

This issue was created by KTable. The KTable syntax I was using was syntactically correct but not working. Refer this question for more information. Changing KTable syntax worked for me. Now, customerKTable returns events or objects from materialized view when Order event arrived.

这篇关于KTable无法从实例化视图获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 01:34