Problem Statment:
Topic 1: "key = empId, value = empname, deptName, ..."
Topic 2: "key = deptName, value = deptName"
I need the data from Topic 1 where the deptName(value attribute in topic 1) is equal to key of Topic 2.
Steps:
- Create a stream from Topic 1, group it by deptName, and do aggregatation.
It will return Ktable
(key =deptName, value = "empId1,empId2,empId3 ..")
- Create a stream from Topic 2
(key ="deptName" value = "deptName")
- Perform a left join operation on Ktable (Step 1) and KSteam (Step2).
(KStream-Ktable)
- And join returns desired result.
Everything works as expected in single partition, however, after switching to multiple partitions, join doesn't return any data.
Step 1:
KGroupedStream<String, Object> groupedStream = adStream.groupBy((key, value) -> value.getOrganizationId().toString());
groupedStream
.aggregate(() -> (new String()),
(aggKey, newValue, aggValue) -> addCurrentValue(aggValue,
String.valueOf(newValue.getOriginId())),
Materialized.as("aggregated-stream-store").with(strSerde, strSerde))
.toStream().to(Constant.AD_AGGREGATED_DATA, Produced.with(strSerde, strSerde));
Step 2:
KStream<String, String> swgOrgStream = builder.stream(Constant.SWG_ORG_TOPIC,Consumed.with(strSerde, strSerde));
Step 3:
KStream<String, String> filteredOrgStream = swgOrgStream.leftJoin(aggregatedTable,
(leftValue, rightValue) -> rightValue);