我描述了输入和输出
public interface UserStream {
String USER_CREATE_EVENT_OUTPUT = "user-event-out";
String USER_IMPORT = "user-import";
String USER_EXPORT = "user-export";
@Output(USER_EVENT_OUTPUT)
MessageChannel userEventOutput();
@Output(USER_EXPORT)
KTable<?, ?> userInput();
@Input(USER_IMPORT)
KTable<?, ?> userOutput();
}
还有处理器
@EnableBinding(UserStream.class)
....
@StreamListener
@SendTo(UserStream.USER_EXPORT)
public KTable<UserIdDto, UserDto> webQuoteUserConsumer(@Input(UserStream.USER_IMPORT) KTable<UserIdDto, WebQuoteUser> users) {
return users
.mapValues((id, user) -> createNewUser(user, id))
.filter((id, user) -> user.isPresent())
.mapValues((id, user) -> mapper.mapToUserDto(user.get()));
}
但是得到了Caused by: java.lang.IllegalStateException: No factory found for binding target type: org.apache.kafka.streams.kstream.KTable among registered factories: channelFactory,messageSourceFactory
好像我在配置中缺少什么。这是我放入yml的内容
spring:
cloud:
stream:
bindings:
user_import:
group: steaming-service-group
destination: user-export-topic
contentType: application/json
consumer:
resetOffsets: true
startOffset: earliest
header-mode: headers
quote_import:
group: steaming-service-group
destination: web-quotes
contentType: application/json
consumer:
resetOffsets: true
startOffset: earliest
header-mode: headers
quote_export:
destination: quote_import-topic
contentType: application/json
producer:
header-mode: headers
....
spring:
cloud:
stream:
kafka:
binder:
brokers: localhost:9092
zkNodes: localhost:2181
streams:
binder:
brokers: localhost:9092
configuration:
default.key.serde: org.apache.kafka.common.serialization.Serdes$StringSerde
default.value.serde: org.apache.kafka.common.serialization.Serdes$StringSerde
commit.interval.ms: 1000
中的代码示例