忽略这个问题,我的代码中有一个问题。
我想使用Spring Cloud Stream在2个不同的主题中生成2种不同的kafka消息。一切工作正常,当我只做一个,但当我试图创建2供应商bean函数,我有一个问题。这是我的application.yaml
server.port: 8087
spring:
application:
name: metrics-producer
cloud:
schema:
avro:
dynamicSchemaGenerationEnabled: true
stream:
default:
contentType: application/*+avro
producer:
useNativeEncoding: true
function:
definition: rowCountSupplier;loadedColumnsSupplier
bindings:
rowCountSupplier-out-0.destination: rowcount
loadedColumnsSupplier-out-0.destination: loadedcolumns
kafka:
bootstrap-servers: localhost:9092
default:
...
然后在启动应用程序时出现以下错误
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'metricsProducer': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'spring.cloud.stream.bindings.rowCountSupplier;loadedColumnsSupplier-out-0.destination' in value "${spring.cloud.stream.bindings.${spring.cloud.stream.function.definition}-out-0.destination}"
看起来不支持;两个供应商的定义是分开的,但文档似乎表明这是可能的。
这对我来说很好。
@SpringBootApplication
public class So72361424Application {
public static void main(String[] args) {
SpringApplication.run(So72361424Application.class, args);
}
@Bean
public Supplier<String> rowCountSupplier() {
return () -> "From rowCountSupplier: " + new Random().nextInt();
}
@Bean
public Supplier<String> loadedColumnsSupplier() {
return () -> "From loadedColumnsSupplier: " + new Random().nextInt();
}
@Bean
public Consumer<String> rowCountConsumer() {
return System.out::println;
}
@Bean
public Consumer<String> loadedColumnsConsumer() {
return System.out::println;
}
}
Configiuration:
spring.cloud.function.definition=rowCountSupplier;loadedColumnsSupplier;rowCountConsumer;loadedColumnsConsumer
spring.cloud.stream.bindings.rowCountConsumer-in-0.destination=rowCountSupplier-out-0
spring.cloud.stream.bindings.loadedColumnsConsumer-in-0.destination=loadedColumnsSupplier-out-0
我看到如下输出:
From loadedColumnsSupplier: -1442588112
From rowCountSupplier: -653426801
From loadedColumnsSupplier: -1397059810
From rowCountSupplier: 1267011618
From rowCountSupplier: 861125412
From loadedColumnsSupplier: 550252583
From rowCountSupplier: 1477875916
From loadedColumnsSupplier: 259212207
...
...
你这边的配置一定有问题。我注意到您正在使用AVRO和本机序列化。您是否提供模式注册表?调试并查看是否发现任何错误。如果您仍然面临问题,请提供可重复的最小样本。