Skip to content

Conversation

muqtadir66
Copy link

Implements Tasks 2–5 of the Forage J.P. Morgan SE simulation by building out Midas Core—a Spring Boot service that ingests, validates, persists, and enriches transactions, and exposes balances via a small read API.

Task 2 – Kafka Integration

  • Added a Spring Kafka listener to consume Transaction messages from the configured topic.
  • Introduced Kafka configuration (consumer/producer factories, JSON (de)serializers, and a ConcurrentKafkaListenerContainerFactory) so the listener receives Transaction objects directly.
  • Verified with Embedded Kafka (TaskTwoTests) and used breakpoints to capture the first four transaction amounts.

Task 3 – H2/JPA Persistence

  • Validated senderId/recipientId and sufficient funds.
  • Applied balance updates atomically in a single DB transaction.
  • Persisted each accepted transaction as a TransactionRecord with many-to-one links to UserRecord (sender/recipient).

Task 4 – Incentive REST API

  • Posted validated Transaction to the external Incentive API; parsed Incentive { amount }.
  • Credited recipients with amount + incentive while senders pay amount only.
  • Stored incentive on each TransactionRecord.

Task 5 – Read API (/balance)

  • Exposed GET /balance?userId=... returning JSON Balance.
  • Returns 0 for unknown users.

Changes (by area):

Kafka (Task 2):

  • src/main/java/com/jpmc/midascore/config/KafkaConfig.java
    Consumer/producer factories, JSON (de)serializers, and ConcurrentKafkaListenerContainerFactory (topic from application.yml).

  • src/main/java/com/jpmc/midascore/component/TransactionListener.java
    @KafkaListener that receives Transaction and delegates to the service layer (used for TaskTwoTests debugging).

Domain & Persistence (Task 3):

  • src/main/java/com/jpmc/midascore/service/TransactionService.java
    Validation → balance updates → persistence (later extended for Task 4).

  • src/main/java/com/jpmc/midascore/entity/TransactionRecord.java
    JPA entity: sender, recipient (many-to-one), amount, incentive.

  • src/main/java/com/jpmc/midascore/repository/TransactionRepository.java
    Repository for TransactionRecord.

External REST (Task 4):

  • src/main/java/com/jpmc/midascore/config/RestConfig.java
    RestTemplate bean (short timeouts).

  • src/main/java/com/jpmc/midascore/foundation/Incentive.java
    DTO for Incentive API response.

Read API (Task 5):

  • src/main/java/com/jpmc/midascore/controller/BalanceController.java
    GET /balance?userId= → returns Balance { amount } JSON.

Config:

  • src/main/resources/application.yml
    Kafka topic property; incentive API URL; JPA/H2 settings; server port for tests.

(Existing scaffold files such as foundation/Transaction.java, foundation/Balance.java, entity/UserRecord.java, repository/UserRepository.java, and MidasCoreApplication.java remain in place.)

Notes:

  • Kafka gives decoupling and burst tolerance; the listener consumes JSON → Transaction via configured deserializers.
  • JPA/H2 ensures transactional integrity for balance updates and keeps the DB backend swappable.
  • Incentive API failures default to incentive 0 (no extra debit to sender).
  • /balance returns 0 for unknown users and preserves Balance.toString() format required by tests.

…tion, /balance endpoint

Task 2: Integrated Kafka into Midas Core; set up KafkaListener to consume Transaction objects; verified via Embedded Kafka (TaskTwoTests) and captured the first four transactions via debugger.

Task 3: Added JPA/H2 integration; validated sender/recipient and funds; updated balances transactionally; persisted TransactionRecord with many-to-one sender/recipient.

Task 4: Integrated external Incentive REST API; posted validated Transaction; credited recipient with (amount + incentive) without additional sender charge; stored incentive on TransactionRecord.

Task 5: Exposed GET /balance?userId=... returning Balance JSON; returns 0 for unknown users; runs alongside Kafka listener.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant