I would like to create a service to access some reference data coming from Kafka in my kafka-streams applications using kafka-streams-binder via GlobalKTable
and the InteractiveQueryService
. That is quite easy when I add that GlobalKTable
as an input in my binding:
@Bean
fun aggregatePositions(interactiveQueryService: InteractiveQueryService): Function<KStream<String, Event>, Function<GlobalKTable<String, ReferenceData>, KStream<String, String>>> {
return Function { eventStream ->
Function { referenceDataTable ->
eventStream
.mapValues { event ->
val store = interactiveQueryService.getQueryableStore(
referenceDataTable.queryableStoreName(),
QueryableStoreTypes.keyValueStore<String, ReferenceData>()
)
"id: ${event.id} - type: ${store.get(event.typeId).typeName}"
}
}
}
}
Since I have various kafka-streams applications which need to resolve that reference data I wanted to extract that somehow to a spring-boot-starter and not actually add that GlobalKTable
as parameter to the binding but make it available in all the bindings somehow.
Is there a good place where to hook into the creation of the topology to add that GlobalKTable to each binding or would it be better to create a separate topology for that and make the statestore available for the binding functions?