Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.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
KTable在Spring Boot应用程序中不返回任何数据,但可以对其进行查询_Spring_Spring Boot_Apache Kafka Streams_Spring Kafka - Fatal编程技术网

KTable在Spring Boot应用程序中不返回任何数据,但可以对其进行查询

KTable在Spring Boot应用程序中不返回任何数据,但可以对其进行查询,spring,spring-boot,apache-kafka-streams,spring-kafka,Spring,Spring Boot,Apache Kafka Streams,Spring Kafka,我有一个使用Kafka Streams的Spring启动应用程序。我有一个KTable,其中包含一些金融货币报价,如下所示: @Bean(name = "indicativeQuotes") public KTable<String, Quote> quoteKTable(StreamsBuilder streamsBuilder) { return streamsBuilder.table(quoteTopicName, Materialized.&

我有一个使用Kafka Streams的Spring启动应用程序。我有一个KTable,其中包含一些金融货币报价,如下所示:

@Bean(name = "indicativeQuotes")
public KTable<String, Quote> quoteKTable(StreamsBuilder streamsBuilder) {
    return streamsBuilder.table(quoteTopicName,
            Materialized.<String,Quote,KeyValueStore<Bytes,byte[]>>as("quoteTable")
                    .withKeySerde(Serdes.String())
                    .withValueSerde(new JsonSerde<>(Quote.class)));
}

但我认为这段代码不起作用,因为它不是处理拓扑的一部分,我不能按需从Ktable获取数据。我在这里有点困惑,当然当事件被触发时,我可以通过存储查询数据,但是对于这种用例,可能有更好的模式吗?基本上,我感兴趣的是是否可以将此触发的作业事件合并为处理管道的一部分。

如果您只想将更新发布到另一个主题,请将KTable转换为KStream并使用to()函数

KTable ktable = ...;
KStream ksteram = ktable.toStream();
kstream.to("topic", Produces.with(keySerde, valueSerde))
该主题将包含该表的更改日志

但是 显然,由于一些与生命周期相关的概念,您不能只注入(
@autowire
)KStream/KTable。您应该尽可能保持与KafkaStreams相关的代码


因此,在您希望在某个“随机”时间内对表的当前状态执行某些操作的特定情况下,您必须查询存储(表)。因此,搜索卡夫卡蒸汽互动查询。请记住,您需要从应用程序的所有实例中获取数据(如果你有超过1个。或者你可以使用全局存储。这需要一两天的搜索时间。

我想这与缓存有关。Cf.嗨,Matthias,谢谢你的回答。阅读此问题后,你的回答是:我想我没有完全掌握流处理的概念。你能看到更新吗?不确定我是否能跟上。你改变了吗他将配置为将缓存大小设置为零,但仍然存在问题?另外,默认情况下,您应该看到大约30秒的输出,默认的提交间隔是多少?提交时缓存被刷新。
@Override
protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
    TriggerKey triggerKey = jobExecutionContext.getTrigger().getKey();
    log.info("Job was triggered by: {}", triggerKey.getName());

    indicativeQuotes.filter((key, value) -> key.equals(triggerKey.getName()))
            .mapValues(quoteToCourseFixedMapper)
            .toStream()
            .peek((instrument, course)-> log.info("Sending courses for instrument: {}, {}", instrument, course))
            .to(quoteEventTopicName);
}
KTable ktable = ...;
KStream ksteram = ktable.toStream();
kstream.to("topic", Produces.with(keySerde, valueSerde))