Skip to content

magicliang/sequence-generator-clean

Repository files navigation

Sequence Generator Clean

A high-performance distributed sequence generator built with Java 8 and Spring Boot.

Features

  • High Performance: In-memory buffer with multi-level caching
  • High Availability: Dual-database failover support
  • Multi-Business Support: Configurable business types with different step sizes
  • Set-Based Deployment: Support for distributed deployment across multiple sets
  • Load Testing Isolation: Separate sequence ranges for load testing
  • RESTful API: Simple HTTP-based interface
  • Monitoring: Built-in health checks and metrics

Quick Start

Prerequisites

  • Java 8 or higher
  • Maven 3.6+

Running the Application

  1. Clone the repository
  2. Navigate to the project directory
  3. Run the application:
mvn spring-boot:run

The application will start on http://localhost:8080/sequence-gen

API Usage

Generate Single Sequence

curl -X POST http://localhost:8080/sequence-gen/api/v1/sequences/generate \
  -H "Content-Type: application/json" \
  -d '{
    "businessType": "ORDER",
    "source": "WEB"
  }'

Generate Batch Sequences

curl -X POST http://localhost:8080/sequence-gen/api/v1/sequences/batch \
  -H "Content-Type: application/json" \
  -d '{
    "businessType": "PAYMENT",
    "batchSize": 10,
    "source": "MOBILE"
  }'

Check System Status

curl http://localhost:8080/sequence-gen/api/v1/admin/status

Configuration

Business Types

Configure business types in application.yml:

business:
  types:
    - name: ORDER
      code: "01"
      description: "Order sequence"
      step: 1000
    - name: PAYMENT
      code: "02"
      description: "Payment sequence"
      step: 500

Database Configuration

The application uses H2 in-memory databases by default. For production, configure your databases:

spring:
  datasource:
    primary:
      url: jdbc:mysql://primary-db:3306/sequences
      username: user
      password: password
    secondary:
      url: jdbc:mysql://secondary-db:3306/sequences
      username: user
      password: password

Architecture

The system consists of several key components:

  • SequenceBuffer: Multi-level caching for high-performance sequence generation
  • SequenceManager: Database operations with automatic failover
  • SequenceGeneratorService: Main business logic
  • REST Controllers: HTTP API endpoints

Monitoring

Access the H2 console at: http://localhost:8080/sequence-gen/h2-console

Health check endpoint: http://localhost:8080/sequence-gen/actuator/health

Testing

Run tests with:

mvn test

License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published