本文介绍了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 Music 示例,我创建了 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 语法对我有用.现在,当 Order 事件到达时,customerKTable 从物化视图返回事件或对象.

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 00:32