我正在嘗試開發一個Spring Boot應用程序,使用該庫對從Kafka主題中讀取的一些消息做出反應。reactor-kafka我有一個構建.KafkaReceiver@Configurationpublic class MyConfiguration { @Bean public KafkaReceiver<String, String> kafkaReceiver() { Map<String, Object> props = new HashMap<>(); // Options initialisation... final ReceiverOptions<String, String> receiverOptions = ReceiverOptions.<String, string>create(props) .subscription(Collections.singleton(consumer.getTopic())); return KafkaReceiver.create(receiverOptions); } }井。?!,F在?使用不那么反應式的庫,我可以用Spring Boot注釋一個方法,Spring Boot將為我創建一個從Kafka主題收聽的線程。spring-kafka@KafkaListener我應該將 放置 在哪里?在所有示例中,我發現直接使用方法,但這不是Boot方式。KafkaReceivermain我正在使用Spring Boot 2.1.3和Reacter-Kafka 1.1.0
1 回答

素胚勾勒不出你
TA貢獻1827條經驗 獲得超9個贊
既然你有那顆豆子,現在你可以這樣做:KafkaReceiver
@Bean
public ApplicationRunner runner(KafkaReceiver<String, String> kafkaReceiver) {
return args -> {
kafkaReceiver.receive()
...
.sunbscribe();
};
}
當準備好時,這個豆子將被踢。有關詳細信息,請參閱其 JavaDocs。ApplicationRunnerApplicationContext
添加回答
舉報
0/150
提交
取消