Commit 2bfc2ecf authored by Reshmi's avatar Reshmi
Browse files

Fixing type casting issue for userId while reading from kafka event

parent 6d9fcf34
1 merge request!8Fixing type casting issue for userId while reading from kafka event
Showing with 11 additions and 2 deletions
+11 -2
......@@ -15,6 +15,7 @@ import org.springframework.stereotype.Component;
import java.io.IOException;
import java.time.Duration;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
@Component
public class kafkaConsumer {
......@@ -68,12 +69,20 @@ public class kafkaConsumer {
if (msg != null && !msg.isEmpty() && !msg.trim().isEmpty()) {
JSONObject json = new JSONObject(record.value());
JSONObject edata = json.getJSONObject("edata");
String userIds = edata.getString("userIds");
Object userIdsObject = edata.get("userIds");
String userId="";
if (userIdsObject instanceof List) {
List<String> userIds = (List<String>) userIdsObject;
userId = userIds.get(0);
} else {
userId = edata.getString("userIds");
}
List<String> userIds = (List<String>)edata.get("userIds");
// Now, you can pass userIds to your method
JSONObject relatedObject = json.getJSONObject("edata").getJSONObject("related");
String courseId = relatedObject.getString("courseId");//do_1139628834519941121286,do_11394806141846323211
logger.info("Processing Kafka message - userId: {}, courseId: {}", userIds, courseId);
api_services.get_hierarchy(courseId, userIds);
api_services.get_hierarchy(courseId, userId);
} else {
logger.warn("Received empty or null message from Kafka");
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment