gpt4 book ai didi

java - Spring 卡夫卡 : Read from two different topics in order

转载 作者:行者123 更新时间:2023-12-01 18:45:24 29 4
gpt4 key购买 nike

Spring Kafka 是否可以按保证的顺序读取不同消费者中的两个不同主题?例如,主题 A 存储与确定如何处理主题 B 中存储的数据相关的信息。主题 A 被读入内存并被引用,但需要在从主题 B 读取数据之前完全填充。下面是我当前的设置示例...

@Service
public class TopicA {
@KafkaListener(topics = "topicA")
public void consume(ConsumerRecord<String, byte[]> record) {
// ... some code here to populate an in-memory data structure
}
}
@Service
public class TopicB {
@KafkaListener(topics = "topicB")
public void consume(ConsumerRecord<String, byte[]> record) {
// ... some code here that depends on topic A having populated the in-memory data structure
}
}

到目前为止,我一直倾向于创建一个 Spring 启动过程(使用 @PostConstruct),该过程首先通过读取主题 A 来初始化数据结构,但一直无法使其正常工作。有没有人有什么建议?提前致谢!

最佳答案

@KafkaListener(id = "bConsumer" topics = "topicB", autoStartup = "false")

然后在准备好后 Autowiring KafkaListenerEndpointRegistry bean 和 registry.getListenerContainer("bConsumer").start();

关于java - Spring 卡夫卡 : Read from two different topics in order,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59851361/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com