微服务项目,应用Eureka, Redis, RabbitMQ
1.设计思路
2.技术架构
(1)Eureka Client:
时间服务(leyouTimeServer,端口号8000):为页面服务提供时间统一的接口。
商品服务(leyouStock,端口号7000):对外提供的接口(商品列表、商品详情、秒杀政策)。
库存服务(leyouStorage,端口号6001):队列监听,在队列中提取消息与数据库交互减少库存。
会员服务(leyouUser,端口号5000):为页面服务提供会员数据接口,会员的添加、修改、登录。
订单服务(leyouOrder,端口号4000):队列监听,在队列中提取消息与数据库交互生成订单。
页面服务(leyouClient,端口号3000):为前端页面提供数据接口。
(2)Eureka Server:
注册中心(leyouServer,端口号9000)各服务都在注册中心进行注册。
配置中心 (leyouConfig):提供所有服务需要的配置。
(3)Redis的应用
(4)RabbitMQ的应用:
3.整体项目目录
4.创建Eureka注册中心(端口号9000),leyouServer
(1)配置pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-parent</artifactId>
<version>2.1.6.RELEASE</version>
</parent>
<groupId>com.itheima</groupId>
<artifactId>leyou</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Greenwich.SR2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
(2)配置文件application.properties
server.port=9000
eureka.client.service-url.defaultZone=http://localhost:9000/eureka/
eureka.instance.hostname=localhost
spring.application.name=leyou-server
#不从服务器拿服务信息
eureka.client.fetch-registry=false
#不在服务端注册
eureka.client.register-with-eureka=false
(3)启动类
① @EnableEurekaServer,意思为启动Eureka服务端
@SpringBootApplication
@EnableEurekaServer
public class ServerApplication {
public static void main(String[] args) {
SpringApplication.run(ServerApplication.class, args);
}
}
5.创建时间服务(端口号8000),leyouTimeServer
(1)pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http:/