I have a topic which receives JSON records with possible partial data. I want to merge this data, so i try to gather as much information as possible within the final data record.
t1: { id: '1234', attribute1: 'foo' }
t2: { id: '1234', attribute2: 'bar' }
desired stream after merging record values:
t1: { id: '1234', attribute1: 'foo' }
t2: { id: '1234', attribute1: 'bar', attribute2: 'bar' }
To achieve this I tried:
//key of the topic is id
KStream<String, MyObject> input = ...
return input.groupByKey().reduce((current, newEvent) -> return newEvent.merge(current)).toStream();
but that yields only a single entry, as groupy/reduce produces a KTable. Is there a possibility to achieve this?
Edit: The stream definition was correct, it appears that reduce by default does not send all messages downstream, but caches them before doing so. To disable this behaviour the configuration property:
cache.max.bytes.buffering: 0
has to be set.