I have an existing stream which uses two topics as its source:
val streamsBuilder = new StreamsBuilder
val stream1 = streamsBuilder.stream[K, V]("topic1")
val stream2 = streamsBuilder.stream[K, V]("topic2")
stream1
.merge(stream2)
.groupByKey
.reduce(reduceValues)
.toStream
.to("result-topic")
The auto-generated name of the StateStore
is KSTREAM-REDUCE-STATE-STORE-0000000003
.
Now I need to add one more topic as a source. However, adding a new source increments a kafka-internal number, causing the StateStore
to be KSTREAM-REDUCE-STATE-STORE-0000000005
. I don't want to lose the current state, so I explicitly provide the name of the old StateStore
:
val streamsBuilder = new StreamsBuilder
val stream1 = streamsBuilder.stream[K, V]("topic1")
val stream2 = streamsBuilder.stream[K, V]("topic2")
val stream3 = streamsBuilder.stream[K, V]("topic3") // new topic
stream1
.merge(stream2)
.merge(stream3) // merge new topic
.groupByKey
.reduce(reduceValues)(Materialized.as("KSTREAM-REDUCE-STATE-STORE-0000000003")
.toStream
.to("result-topic")
It seems to work, but I'm not sure if I'm interfering with the Kafka internals because:
- I'm using a custom name in the form of what Kafka would auto-generate (possibility of a name conflict?)
- The set of streams used to feed this
StateStore
is different than what it was initially.
Any comments?