Skip to content

charity1475/batch-processing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Batch Processing Demo

A Spring Batch application that reads customer data from SQL source, transforms it, and sends HTTP requests with XML payload.

Deps & Libs

  • Spring Boot 3.5.3
  • Spring Batch
  • Spring Data JPA
  • JAXB for XML processing
  • H2 Database (for development)
  • PostgreSQL (for production)
  • Kubernetes for deployment

Running Locally

Prerequisites

  • Java 21
  • Maven

Steps

  1. Clone the repository
  2. Build the application:
    mvn clean package
    
  3. Run the application:
    java -jar target/batch-processing-0.0.1-SNAPSHOT.jar
    

The application will:

  1. Initialize an in-memory H2 database with sample customer data
  2. Execute the batch job to process the data
  3. Send HTTP requests with XML payload to the configured endpoint
  4. Exit automatically after job completion

Configuration

The application can be configured through application.properties:

# Database Configuration
spring.datasource.url=jdbc:h2:mem:batchdb
spring.datasource.username=sa
spring.datasource.password=

# Target API endpoint
app.target.url=https://example.com/api/customers

Kubernetes Deployment

The application includes a Kubernetes CronJob configuration that runs the job once per hour.

Prerequisites

  • Kubernetes cluster
  • Docker registry to store the application image

Steps

  1. Build the Docker image:

    docker build -t batch-processing:latest .
    
  2. Push the image to your registry:

    docker tag batch-processing:latest your-registry/batch-processing:latest
    docker push your-registry/batch-processing:latest
    
  3. Update the image reference in k8s-cronjob.yaml

  4. Create the database credentials secret:

    kubectl create secret generic db-credentials \
      --from-literal=username=postgres \
      --from-literal=password=your-password
    
  5. Apply the CronJob configuration:

    kubectl apply -f k8s-cronjob.yaml
    

Project Structure

  • src/main/java/com/megasoft/batch_processing/model/ - Data models
  • src/main/java/com/megasoft/batch_processing/repository/ - Database repositories
  • src/main/java/com/megasoft/batch_processing/service/ - Services for HTTP requests
  • src/main/java/com/megasoft/batch_processing/config/ - Batch job configuration
  • src/main/java/com/megasoft/batch_processing/BatchProcessingApplication.java - Main application class

About

Batch Processing

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published