This project is a sample Spring Cloud application that implements a microservices architecture with services like product and order management, and an API gateway for service routing.
- Java JDK 1.8
- Maven
- MySQL Server
- Nacos Service Discovery
- Alibaba Sentinel
- Jmeter
Ensure Java and Maven are installed on your system and the JAVA_HOME
environment variable is set.
- Clone the repository to your local machine.
- Create MySQL databases
shop_product
andshop_order
. - Start the Nacos Service Discovery and Configuration server. 4.Start the Alibaba sentinel and Jemeter to pull Http request.
The project includes the following microservices:
- shop-product-api: The API definition for the product service.
- shop-product-server: Implementation of the product service.
- shop-order-api: The API definition for the order service.
- shop-order-server: Implementation of the order service.
- api-gateway: The gateway service that routes API requests to the appropriate microservice.\
Each service has its own application.yml
or application.properties
file in the src/main/resources
directory where you can set up the datasource, server port, and other configurations.
server.port
: The port on which the service will run.spring.application.name
: The name of the application in the service registry.spring.datasource
: The datasource configuration.spring.jpa
: The JPA/Hibernate configuration.spring.cloud.nacos.discovery.server-addr
: The address of the Nacos server.
Each microservice can be started with the Spring Boot Maven plugin. Below are the commands to start each service:
cd api-gateway
mvn spring-boot:run
To start the shop-product-api
, run the following command:
cd shop-product-api
mvn spring-boot:run
To start the shop-product-server, use this command:
cd shop-product-server
mvn spring-boot:run
Start the shop-order-api with:
cd shop-order-api
mvn spring-boot:run
To launch the shop-order-server, execute:
cd shop-order-server
mvn spring-boot:run
sh startup.sh -m standalone
startup.cmd -m standalone
Alibaba Sentinel provides a dashboard for monitoring and managing rules in a graphical interface.
To start the Sentinel dashboard, execute the following command in the directory where Sentinel is located
java -Dserver.port=8080 -jar sentinel-dashboard-1.8.0.jar
Apache JMeter is an open-source load testing tool. You can use it to test the performance and stability of your services under different load conditions.
- Download and install Apache JMeter.
- Open JMeter GUI by running the
jmeter
command in thebin
directory of JMeter. - Configure your test plan by adding Thread Groups, HTTP Request samplers, listeners, etc.
- In JMeter, create a new Test Plan.
- Add a Thread Group to define the number of users and ramp-up period.
- Add an HTTP Request sampler to set up requests to your services.
- Add a Listener (e.g., View Results in Table) to view the results.
- Start the test by clicking the 'Start' button (green play icon).
To integrate JMeter with Sentinel, you need to:
- Add the Sentinel dependency to your project's
pom.xml
. - Configure Sentinel resource rules in your application.
- Run your JMeter tests and observe the results on the Sentinel dashboard.