What is the Soul?
一個異步的,高性能的,跨語言的,回應式的API網關,我希望能夠有一樣東西像靈魂一樣,保護您的微服務,參考了Kong,Spring-Cloud-Gateway等優秀的網關后,站在巨人的肩膀上,Soul由此誕生!
是不是很吊的一句話,站在巨人身上那么這些巨人也就變成了矮子,
整體架構如下圖所示:

是不是很炫反正我是沒看懂
部署單機版

操作在windows環境
安裝SoulAdmin
souladmin:控制臺,負責維護網關的元資料、配置等等,并提供給 SoulBootstrap 網關服務讀取,
在mysql資料庫中執行下面圖中sql,12張表


在瀏覽器輸入https://yu199195.github.io/jar/soul-admin.jar 回車下載即可,yml檔案復制一份在外部啟動,用自己的資料庫
啟動命令:java -jar soul-admin.jar --spring.config.location=xxxxx\application-local.yml

啟動成功后
通過日志看到 Soul Admin 啟動在 9095 埠,使用瀏覽器,訪問 http://127.0.0.1:9095/ 地址,進入登錄頁,賬號密碼分別是:admin 和123456


安裝SoulBootstrap
SoulBootstrap:網關服務,負責啟動網關,并轉發請求到后端服務,
在瀏覽器輸入https://yu199195.github.io/jar/soul-bootstrap.jar 回車下載即可,yml檔案復制一份在外部啟動,用自己的資料庫
啟動命令:java -jar soul-bootstrap.jar --soul.sync.websocket.url="ws://localhost:9095/websocket",如下圖表示啟動成功

使用瀏覽器,訪問 http://127.0.0.1:9195
![]()
引入網關對http的代理插件
針對其他方式參考官方檔案:https://dromara.org/website/zh-cn/docs/soul/user-http.html
官方代碼gitee地址:https://github.com/Dromara/soul/tree/master
soul網關使用 divide 插件來處理http請求

SpringBoot專案
pom依賴
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<spring.boot.version>2.2.4.RELEASE</spring.boot.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>${spring.boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- 引入 SpringMVC 相關依賴,并實作對其的自動配置 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.dromara</groupId>
<artifactId>soul-spring-boot-starter-client-springmvc</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.dromara</groupId>
<artifactId>soul-client-springmvc</artifactId>
<version>2.2.0</version>
</dependency>
</dependencies>
yml中solu配置
soul:
http:
adminUrl: http://localhost:9095
port: 8080
contextPath: /boot
appName: soulboot
full: false
啟動項
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
controller層
import org.dromara.soul.client.springmvc.annotation.SoulSpringMvcClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/user")
@SoulSpringMvcClient(path = "/user")
public class UserController {
private Logger logger = LoggerFactory.getLogger(getClass());
@GetMapping("/get")
@SoulSpringMvcClient(path = "/get")
public String getUser(@RequestParam("id") Integer id) {
return "DEMO:" + id;
}
@PostMapping("/create")
public Integer createUser(@RequestBody UserCreateDTO createDTO) {
logger.info("[createUser][username({}) password({})]", createDTO.getNickname(), createDTO.getGender());
return 1;
}
}
dao層
public class UserCreateDTO {
/**
* 昵稱
*/
private String nickname;
/**
* 性別
*/
private Integer gender;
public String getNickname() {
return nickname;
}
public UserCreateDTO setNickname(String nickname) {
this.nickname = nickname;
return this;
}
public Integer getGender() {
return gender;
}
public UserCreateDTO setGender(Integer gender) {
this.gender = gender;
return this;
}
}
啟動后出現下圖表示成功

HTTP API 方法的元資料到 Soul Admin 控制臺,啟動后慧自動配置

然后在postman請求

通過網關bootstrap轉發到后臺


上面就是對soul對springboot配置的網關,未完待續,,,,,,
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/241492.html
標籤:其他
下一篇:軟體體系結構基礎
