类似于设计模式中的Facade模式
- 身份验证和安全
- 审查和检测
- 动态路由
- 压力测试
- 负载均衡(Dubbo自带)
- 静态相应处理
在项目中复制一份guns-rest
模块并重命名为guns-gateway
,修改其pom.xml
,并在主模块 pom.xml
中添加guns-gateway
。
<modules>
<module>guns-admin</module>
<module>guns-core</module>
<module>guns-rest</module>
<module>guns-generator</module>
<module>guns-gateway</module>
</modules>
在guns-gateway
模块的pom.xml
文件中添加Dubbo
和ZooKeeper
的依赖:
<dependency>
<groupId>com.alibaba.spring.boot</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.101tec</groupId>
<artifactId>zkclient</artifactId>
<version>0.11</version>
</dependency>
在application.yml
中添加:
spring:
application:
name: cinema-gateway
dubbo:
server: true
registry: zookeeper://localhost:2181
在启动类上添加注解@EnableDubboConfiguration
。
-
在项目中复制一份
guns-core
模块并重命名为guns-api
; -
修改其
pom.xml
文件,删除所有依赖,并在主模块的pom.xml
中添加guns-api
;<modules> <module>guns-admin</module> <module>guns-core</module> <module>guns-rest</module> <module>guns-generator</module> <module>guns-gateway</module> <module>guns-api</module> </modules>
-
删除其
java
目录下所有包,创建api
目录,用于存放公用接口类; -
执行
maven install
,编译项目构建至本地仓库,使项目其他模块可以引用guns-api
的jar包;在主模块中添加依赖:
<dependency> <groupId>com.stylefeng</groupId> <artifactId>guns-api</artifactId> <version>${guns.version}</version> </dependency>
其他模块中引入依赖:
<dependency> <groupId>com.stylefeng</groupId> <artifactId>guns-api</artifactId> </dependency>
此时,接口类只需要在
guns-api
中写一份就够了,避免了冗余,即抽离业务 API。