How nageoffer/12306 works
Purpose and deployment modes
A JDK 17, Spring Boot 3/Spring Cloud railway-ticketing system covering identity, passengers, ticket search/purchase, orders, payment, refunds, and gateway access. Maven is the backend build root (pom.xml). It supports:
• Microservices: independently run gateway, user, ticket, order, and payment applications under services/.
• Aggregated deployment/demo mode: run aggregation plus gateway via services/aggregation-service/src/main/java/org/opengoofy/index12306/biz/aggregationservice/AggregationServiceApplication.java and services/gateway-service/src/main/java/org/opengoofy/index12306/biz/gatewayservice/GatewayServiceApplication.java.
A Vue console is a separate SPA entry point at console-vue/src/main.js, with routes and HTTP access in console-vue/src/router/index.js and console-vue/src/service/axios.js.
Edge, identity, and user domain
The gateway is the public request boundary, routing requests and validating JWTs before downstream services. TokenValidateGatewayFilterFactory extracts/validates user context; the shared user starter can propagate it between services.
• services/gateway-service/src/main/java/org/opengoofy/index12306/biz/gatewayservice/filter/TokenValidateGatewayFilterFactory.java
• frameworks/bizs/user/src/main/java/org/opengoofy/index12306/frameworks/starter/user/core/UserTransmitFilter.java
• services/user-service/src/main/java/org/opengoofy/index12306/biz/userservice/controller/UserLoginController.java
User service owns registration, login, profile, and passenger records. Registration uses a responsibility chain and a Redis-backed Bloom-filter configuration to protect high-volume username checks.
• services/user-service/src/main/java/org/opengoofy/index12306/biz/userservice/service/handler/filter/user/UserRegisterCreateChainFilter.java
• services/user-service/src/main/java/org/opengoofy/index12306/biz/userservice/config/RBloomFilterConfiguration.java
• services/user-service/src/main/java/org/opengoofy/index12306/biz/userservice/controller/PassengerController.java
Ticket inventory and purchase orchestration
Ticket service owns train, station, carriage, seat, fare, and availability data, and exposes query and purchase APIs. Purchase first runs validation/stock/repeat-request chain stages, then selects a seat-class strategy/template and allocates physical seats. Availability is protected by a Redis/Lua token bucket with explicit rollback.
• services/ticket-service/src/main/java/org/opengoofy/index12306/biz/ticketservice/controller/TicketController.java
• services/ticket-service/src/main/java/org/opengoofy/index12306/biz/ticketservice/service/handler/ticket/filter/purchase/TrainPurchaseTicketChainFilter.java
• services/ticket-service/src/main/java/org/opengoofy/index12306/biz/ticketservice/service/handler/ticket/tokenbucket/TicketAvailabilityTokenBucket.java
Purchase crosses service boundaries: ticket service calls user data, creates an order remotely, and obtains payment information. It also consumes delayed-close and payment-result events to restore or finalize inventory.
• services/ticket-service/src/main/java/org/opengoofy/index12306/biz/ticketservice/remote/TicketOrderRemoteService.java
• services/ticket-service/src/main/java/org/opengoofy/index12306/biz/ticketservice/mq/consumer/DelayCloseOrderConsumer.java
Orders, payment, and asynchronous lifecycle
Order service persists orders, items, and passenger relations; it provides creation, cancellation, detail, and paginated query APIs. It publishes delayed order-close events and consumes payment/refund callbacks to advance order state.
• services/order-service/src/main/java/org/opengoofy/index12306/biz/orderservice/controller/TicketOrderController.java
• services/order-service/src/main/java/org/opengoofy/index12306/biz/orderservice/mq/produce/DelayCloseOrderSendProduce.java
• services/order-service/src/main/java/org/opengoofy/index12306/biz/orderservice/mq/consumer/PayResultCallbackOrderConsumer.java
Payment service is the external payment boundary: it creates payments/refunds, handles provider callbacks, and emits RocketMQ result events for order reconciliation. The concrete provider integration is Alipay.
• services/pay-service/src/main/java/org/opengoofy/index12306/biz/payservice/controller/PayCallbackController.java
• services/pay-service/src/main/java/org/opengoofy/index12306/biz/payservice/handler/AliPayNativeHandler.java
• services/pay-service/src/main/java/org/opengoofy/index12306/biz/payservice/mq/produce/PayResultCallbackOrderSendProduce.java
Persistence, cache, and consistency infrastructure
Each bounded service owns DAOs/entities and uses MyBatis-Plus plus ShardingSphere configurations; order, pay, and user services define domain-specific database/table sharding algorithms. SQL bootstrap schemas are supplied under resources/db/.
• services/order-service/src/main/resources/shardingsphere-config.yaml
• services/pay-service/src/main/java/org/opengoofy/index12306/biz/payservice/dao/algorithm/PayTableComplexAlgorithm.java
• resources/db/12306-springcloud-ticket.sql
Redis supports distributed cache, multistage cache, Lua atomic operations, Bloom filters, distributed-ID worker allocation, and ticket tokens. RocketMQ carries delayed closure and payment/refund outcomes. Canal/binlog consumers update ticket cache/token state after database changes.
• frameworks/cache/src/main/java/org/opengoofy/index12306/framework/starter/cache/MultistageCache.java
• frameworks/distributedid/src/main/java/org/opengoofy/index12306/framework/starter/distributedid/core/snowflake/LocalRedisWorkIdChoose.java
• services/ticket-service/src/main/java/org/opengoofy/index12306/biz/ticketservice/canal/TicketAvailabilityCacheUpdateHandler.java
Shared platform conventions
frameworks/ is an internal Spring Boot starter layer, not business ownership: it standardizes result/error handling, web exception handling, authentication context, caching, IDs, idempotency, logging, database metadata, and reusable chain/strategy/template patterns. Auto-configurations are registered through Spring Boot imports.
• frameworks/web/src/main/java/org/opengoofy/index12306/framework/starter/web/GlobalExceptionHandler.java
• frameworks/idempotent/src/main/java/org/opengoofy/index12306/framework/starter/idempotent/core/IdempotentAspect.java
• frameworks/designpattern/src/main/java/org/opengoofy/index12306/framework/starter/designpattern/chain/AbstractChainContext.java
Main entry points: GatewayServiceApplication.java API Gateway · TicketController.java Ticket service · PayCallbackController.java Payment service · UserLoginController.java User service
Components 18
Clients
- Vue Console
console-vue/src/main.js
Business services
- API Gateway · Public routing and JWT validation boundary.
services/gateway-service/src/main/java/org/opengoofy/index12306/biz/gatewayservice/GatewayServiceApplication.java - JWT filter
services/gateway-service/src/main/java/org/opengoofy/index12306/biz/gatewayservice/filter/TokenValidateGatewayFilterFactory.java - Aggregation service · Aggregated demo deployment entry point.
services/aggregation-service/src/main/java/org/opengoofy/index12306/biz/aggregationservice/AggregationServiceApplication.java - User service · Owns accounts, profiles, and passengers.
services/user-service/src/main/java/org/opengoofy/index12306/biz/userservice/controller/UserLoginController.java - Registration guard · Protects high-volume username checks.
services/user-service/src/main/java/org/opengoofy/index12306/biz/userservice/service/handler/filter/user/UserRegisterCreateChainFilter.java - Ticket service · Owns train, fare, seat, and availability APIs.
services/ticket-service/src/main/java/org/opengoofy/index12306/biz/ticketservice/controller/TicketController.java - Purchase allocator · Validates requests and allocates seats.
services/ticket-service/src/main/java/org/opengoofy/index12306/biz/ticketservice/service/handler/ticket/filter/purchase/TrainPurchaseTicketChainFilter.java - Availability token bucket · Reserves and rolls back ticket availability.
services/ticket-service/src/main/java/org/opengoofy/index12306/biz/ticketservice/service/handler/ticket/tokenbucket/TicketAvailabilityTokenBucket.java - Order service · Persists orders, items, and passenger relations.
services/order-service/src/main/java/org/opengoofy/index12306/biz/orderservice/controller/TicketOrderController.java - Payment service · Creates payments/refunds and receives provider callbacks.
services/pay-service/src/main/java/org/opengoofy/index12306/biz/payservice/controller/PayCallbackController.java - Alipay
services/pay-service/src/main/java/org/opengoofy/index12306/biz/payservice/handler/AliPayNativeHandler.java
Shared platform
Internal Spring Boot starter layer.
- User context propagation
frameworks/bizs/user/src/main/java/org/opengoofy/index12306/frameworks/starter/user/core/UserTransmitFilter.java - Platform patterns · Idempotency, cache, IDs, exceptions, and chain/strategy patterns.
frameworks/designpattern/src/main/java/org/opengoofy/index12306/framework/starter/designpattern/chain/AbstractChainContext.java
Data and messaging
- Redis · Supports cache, tokens, Bloom filters, Lua, and worker IDs.
- RocketMQ · Carries delayed close and payment/refund outcomes.
- Sharded databases · Service-owned persistence with domain sharding.
services/order-service/src/main/resources/shardingsphere-config.yaml - Canal cache updater · Updates ticket cache and tokens after data changes.
services/ticket-service/src/main/java/org/opengoofy/index12306/biz/ticketservice/canal/TicketAvailabilityCacheUpdateHandler.java
Connections 29
- Vue Console → API Gateway: HTTP API
- API Gateway → JWT filter: validates JWT
- JWT filter → User context propagation: establishes context
- API Gateway → Aggregation service: aggregated mode
- API Gateway → User service: routes identity APIs
- API Gateway → Ticket service: routes ticket APIs
- API Gateway → Order service: routes order APIs
- API Gateway → Payment service: routes payment APIs
- User service → Registration guard: registration flow
- Registration guard → Redis: username Bloom filter
- Ticket service → Purchase allocator: purchase request
- Purchase allocator → Availability token bucket: reserve availability
- Availability token bucket → Redis: atomic Lua tokens
- Ticket service → User service: reads passenger data
- Ticket service → Order service: creates order remotely
- Order service → RocketMQ: delayed close event
- Payment service → Alipay: provider integration
- Alipay → Payment service: payment callback
- Payment service → RocketMQ: payment/refund result
- RocketMQ → Order service: advance order state
- RocketMQ → Ticket service: finalize or restore stock
- User service → Sharded databases: owns data
- Ticket service → Sharded databases: owns inventory data
- Order service → Sharded databases: owns orders
- Payment service → Sharded databases: owns payments
- Canal cache updater → Redis: refreshes ticket state
- Sharded databases → Canal cache updater: binlog changes
- Platform patterns → User service: shared conventions
- Platform patterns → Ticket service: shared conventions