Prerequisites
Before you begin, ensure you have the following installed:- Java 8 or higher
- Docker (for MySQL and RabbitMQ)
- Gradle (or use the included Gradle wrapper)
- Git
Setup Infrastructure
The Order Service depends on RabbitMQ and Zipkin for messaging and distributed tracing. You’ll need to set these up first.Start RabbitMQ
RabbitMQ only needs to be started once for all Ecommerce services. It will run on port 5672.
Run the Service Locally
Start the service
- Clean the build directory
- Start a local MySQL database using Docker Compose (port 13306)
- Launch the Spring Boot application on port 8080
- Enable remote debugging on port 5005
Configuration
The service runs with thelocal profile by default, which uses these settings:
Make Your First API Call
Now that the service is running, let’s create an order.Create an Order
The
items array must contain at least one item. Each item requires:productId: A unique product identifier (string)count: Quantity (must be at least 1)itemPrice: Unit price (decimal)
Retrieve an Order
Use the order ID from the previous step:List All Orders
Retrieve a paginated list of orders:Update Product Count
Change the quantity of a product in an order:Pay for an Order
Submit a payment for an order:PAID.
Update Delivery Address
Change the detailed address for an order:Available API Endpoints
Here’s a summary of all available endpoints:| Method | Endpoint | Description |
|---|---|---|
| POST | /orders | Create a new order |
| GET | /orders/{id} | Retrieve an order by ID |
| GET | /orders | List orders (paginated) |
| POST | /orders/{id}/products | Update product count |
| POST | /orders/{id}/payment | Pay for an order |
| POST | /orders/{id}/address/detail | Update delivery address detail |
Useful Commands
Build and Test
Build and Test
Run the full build with all tests:This will:
- Stop any existing Docker containers
- Clean the build directory
- Run unit tests, component tests, and API tests
- Build the application
Database Management
Database Management
Stop MySQL and clear data:Clear MySQL data without stopping:Login to MySQL:Manually start MySQL:
Development Tools
Development Tools
Generate IntelliJ IDEA project:This will automatically open the project in IntelliJ IDEA.Remote debugging:
The service is configured to listen on port 5005 for remote debugging. Configure your IDE to connect to
localhost:5005.Next Steps
Now that you have the service running locally, you can:- Explore the API Reference for detailed endpoint documentation
- Learn about the architecture and design patterns used in the service
- Set up configuration options for database, RabbitMQ, and application properties
- Deploy the service to different environments using the deployment guide
Troubleshooting
Port already in use
Port already in use
If you see an error about port 8080 or 13306 being in use:
-
Check if another instance is running:
-
Stop the conflicting service or change the port in
application-local.yml
RabbitMQ connection failed
RabbitMQ connection failed
Ensure RabbitMQ is running:If it’s not running, restart it from the devops repository:
MySQL connection issues
MySQL connection issues
The service automatically starts MySQL via Docker Compose. If you encounter issues:
-
Check Docker is running:
-
Manually start the database:
-
Check the logs for errors: