Soul Gateway

The target

  • Introduction to Soul Gateway
  • Soul Gateway features
  • Soul Gateway architecture diagram
  • Build the Soul gateway environment locally
  • Use the Soul proxy Http interface
  • conclusion

Introduction to Soul Gateway

This is an asynchronous, high-performance, cross-language, responsive API gateway. I wish there was something like a soul to protect your microservices. After referring to Kong, Spring-cloud-Gateway and other excellent gateways, standing on the shoulders of giants, Soul was born!

Soul Gateway features

  • Support various languages (HTTP protocol), support dubbo, SpringCloud protocol.

  • Plug-in design idea, plug-in hot plug, easy to expand.

  • Flexible flow filtering, can meet all kinds of flow control.

  • Built-in rich plug-in support, authentication, limiting, fuses, firewalls and more.

  • Dynamic traffic configuration, high performance, gateway consumption in 1~2ms.

  • Supports cluster deployment, A/B Test, and blue-green release.

Soul Gateway architecture diagram

Build the Soul gateway environment locally

  • Pull code from Github and compile locally
> git clone https://github.com/Dromara/soul.git

> cd soul

> mvn -DskipTests clean install -U
Copy the code

Because the project is large, it may take a long time to install. Therefore, you need to skip some code checks, unit tests, etc., and run the following command

mvn clean package install -Dmaven.test.skip=true -Dmaven.javadoc.skip=true -Drat.skip=true -Dcheckstyle.skip=true
Copy the code
  • Idea open the Soul project

  • Modify the application.yml file

1. Modify the database address, user name, and password

Datasource: URL: JDBC :mysql:// useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=CONVERT_TO_NULL&failOverReadOnly=false&autoReconnect=true&u SeSSL =false username: indicates your username. Password: indicates your passwordCopy the code
  • Start the
Start the soul-admin project SoulAdminBootstrap Start the soul-Bootstrap project SoulBootstrapApplicationCopy the code
  • Access to the soul – the admin
http://localhost:9095/index.html username: admin password: 123456Copy the code

Successful startup, silky smooth

Use the Soul proxy Http interface

Build your soul gateway based on Springboot

  • pom
<properties> <maven.compiler.source>8</maven.compiler.source> <maven.compiler.target>8</maven.compiler.target> <soul-version>2.2.1</soul-version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> < artifactId > spring - the boot - starter - webflux < / artifactId > < version > 2.2.2. RELEASE < / version > < / dependency > < the dependency > <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> The < version > 2.2.2. RELEASE < / version > < / dependency > <! --soul gateway start--> <dependency> <groupId>org.dromara</groupId> <artifactId>soul-spring-boot-starter-gateway</artifactId> <version>${soul-version}</version> </dependency> <! --soul data sync start use websocket--> <dependency> <groupId>org.dromara</groupId> <artifactId>soul-spring-boot-starter-sync-data-websocket</artifactId> <version>${soul-version}</version> </dependency> <! --if you use http proxy start this--> <dependency> <groupId>org.dromara</groupId> <artifactId>soul-spring-boot-starter-plugin-divide</artifactId> <version>${soul-version}</version> </dependency> <dependency> <groupId>org.dromara</groupId> <artifactId>soul-spring-boot-starter-plugin-httpclient</artifactId> <version>${soul-version}</version> </dependency> </dependencies>Copy the code
  • Writing a startup class
@SpringBootApplication public class SoulBootstrapApplication { public static void main(String[] args) { SpringApplication.run(SoulBootstrapApplication.class, args); }}Copy the code
  • Start soul-admin and SoulBootstrapApplication

Create SpringMvc project based on SpringBoot and integrate with Soul gateway

  • Pom depends on
<! <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <! <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <scope>compile</scope> </dependency> <dependency> <groupId>org.dromara</groupId> <artifactId>soul-spring-boot-starter-client-springmvc</artifactId> <version>${soul-version}</version> </dependency>Copy the code
  • Yml configuration
server:
  port: 8085
soul:
  http:
    adminUrl: http://localhost:9095
    port: 8085
    contextPath: /soul
    appName: http
    full: false
Copy the code
  • The Controller to write

/test/** indicates that all interfaces of the current class will be proxied

@RestController @RequestMapping("/test") @SoulSpringMvcClient(path = "/test/**") public class SoulTestController { @PostMapping("/hello") public String hello(String req) { return req; }}Copy the code
  • Start the visit

    • Direct access to the URL: http://localhost:8085/test/hello

    • Soul proxy URL: http://localhost:8080/soul/test/hello

conclusion

  • The Soul gateway is oneasynchronous.high-performance.Cross language.responsiveAPI gateway;
  • The Soul gateway supports a variety of Http protocols for various languages, common Java RPC calls can also support.
  • Soul gateway adopts plug-in, hot-plug idea to provide rich plug-ins, and can develop their own customized plug-ins;
  • The Soul gateway has high performance;
  • Soul is easy to integrate, and apis are published automatically.