Overview
The Orders Service is the core transactional service in Argos Mesh that manages the product catalog and processes customer orders. It handles CRUD operations for products, inventory management, and publishes events to RabbitMQ for downstream processing by other services.The Orders Service runs on port 8080 and connects to PostgreSQL for data persistence and RabbitMQ for event-driven communication.
Architecture
Service Responsibilities
Product Management
Create, read, update, and delete product records with validation
Order Processing
Handle product sales with stock validation and IP tracking
Event Publishing
Publish product and sales events to RabbitMQ after transaction commit
Security Integration
Check Redis blacklist to block suspicious IP addresses
REST API Endpoints
TheProductController exposes the following RESTful endpoints:
Product Operations
- Get Product
- Create Product
- Update Product
- Delete Product
- Sell Product
GET /orders/products/{id}Retrieves a product by its ID.Response: ProductResponse with product detailsCore Components
Product Entity
TheProduct entity represents a product in the database:
productID: Auto-generated primary keyproductName: Required, non-blank product nameproductPrice: Must be positive decimal valueproductStock: Non-negative integer for inventory count
Product Repository
The repository includes a custom method for pessimistic locking during sales:The
findByIdForUpdate method uses pessimistic write locking to prevent race conditions during concurrent sales transactions.Product Service Implementation
TheProductServiceImpl class contains the core business logic:
IP Blacklist Check
When processing a sale, the service first checks if the client IP is blacklisted in Redis:
Event Publishing
TheProductMessagePublisher handles asynchronous message publishing to RabbitMQ:
The
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) annotation ensures that events are only published to RabbitMQ after the database transaction successfully commits, maintaining data consistency.RabbitMQ Configuration
The service configures the following RabbitMQ resources:Queues and Bindings
Sales Queue
Queue:
argos.sales.queueRouting Key: shop.event.soldReceives ProductSoldInternalEvent messages consumed by the Sentinel serviceProducts Queue
Queue:
argos.products.mgmt.queueRouting Key: shop.event.product.#Receives product lifecycle events (create, update, delete)Event Schema
ProductSoldInternalEvent
productID: The ID of the product that was soldquantity: Number of units purchasedipAddress: Client IP address for DDoS detectiontimeStamp: Timestamp of the sale
Database Configuration
The service connects to PostgreSQL with the following configuration:Error Handling
The service implements custom exceptions for common error scenarios:ProductNotFoundException
Thrown when a product ID doesn’t exist
NotSuficientStockException
Thrown when insufficient inventory is available
SecurityException
Thrown when a blacklisted IP attempts a purchase
Integration Points
Next Steps
Sentinel Service
Learn how Sentinel monitors traffic from Orders
Message Broker
Explore the RabbitMQ event infrastructure