Summary:
When executing TaskTwoTests, the Kafka consumer correctly detects and binds to the dynamic embedded Kafka port, but the KafkaProducer fails to establish a connection because it attempts to connect to the hardcoded/default localhost:9092.
Detailed Behavior:
- The @embeddedkafka environment assigns a randomized dynamic port at runtime.
- The default KafkaTemplate utilized by KafkaProducer ignores the test environment properties and falls back to localhost:9092, resulting in continuous connection timeout warnings and disconnect loops (Node -1 disconnected).
- Students have to manually create a custom @configuration class (KafkaConfig.java) with an explicit KafkaTemplate bean to override this behavior, which adds unnecessary friction to the assignment.
Workaround Applied:
To resolve this locally and pass the test, I had to create a new config package inside com.jpmc.midascore and define a custom KafkaConfig class with an explicit KafkaTemplate<String, Transaction> bean mapped to ${spring.embedded.kafka.brokers}:
- Package:
com.jpmc.midascore.config
- Class:
KafkaConfig.java (handling explicit producer factory and kafka template bindings).
Expected Behavior:
The base repository setup should seamlessly wire the KafkaProducer and KafkaTemplate to the embedded Kafka instance during tests without requiring students to write custom infrastructure configuration code.
Suggested Improvement for Repository:
Consider adding a @TestConfiguration or @DynamicPropertySource directly in the test suite utilities to automatically map the producer factory and template to ${spring.embedded.kafka.brokers} out-of-the-box, saving students from writing extra configuration boilerplate.
Summary:
When executing TaskTwoTests, the Kafka consumer correctly detects and binds to the dynamic embedded Kafka port, but the KafkaProducer fails to establish a connection because it attempts to connect to the hardcoded/default localhost:9092.
Detailed Behavior:
Workaround Applied:
To resolve this locally and pass the test, I had to create a new
configpackage insidecom.jpmc.midascoreand define a customKafkaConfigclass with an explicitKafkaTemplate<String, Transaction>bean mapped to${spring.embedded.kafka.brokers}:com.jpmc.midascore.configKafkaConfig.java(handling explicit producer factory and kafka template bindings).Expected Behavior:
The base repository setup should seamlessly wire the KafkaProducer and KafkaTemplate to the embedded Kafka instance during tests without requiring students to write custom infrastructure configuration code.
Suggested Improvement for Repository:
Consider adding a @TestConfiguration or @DynamicPropertySource directly in the test suite utilities to automatically map the producer factory and template to ${spring.embedded.kafka.brokers} out-of-the-box, saving students from writing extra configuration boilerplate.